Created
October 30, 2013 15:33
-
-
Save ehedaya/7234639 to your computer and use it in GitHub Desktop.
Try period-laced variations of an input email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validateEmail = function(email) { | |
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | |
return re.test(email); | |
} | |
emailPeriodPossibilities = function(str) { | |
if(!validateEmail(str)) { return false } | |
var name = str.match(/^([^@]*)@/)[1]; | |
var domain = str.match(/^([^@]*)@(.*)/)[2]; | |
matches = []; | |
for(var i=1;i<name.length;i++) { | |
var firstHalf = name.substr(0,i); | |
var secondHalf = name.substr(i); | |
matches.push(firstHalf+'.'+secondHalf+'@'+domain); | |
} | |
return matches; | |
}; | |
var e = emailPeriodPossibilities('[email protected]'); | |
console.log(e); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment