Skip to content

Instantly share code, notes, and snippets.

@ehedaya
Created October 30, 2013 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehedaya/7234639 to your computer and use it in GitHub Desktop.
Save ehedaya/7234639 to your computer and use it in GitHub Desktop.
Try period-laced variations of an input email
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('username@domain.com');
console.log(e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment