Skip to content

Instantly share code, notes, and snippets.

@robertklep
Created April 12, 2013 10:48
Show Gist options
  • Save robertklep/5371203 to your computer and use it in GitHub Desktop.
Save robertklep/5371203 to your computer and use it in GitHub Desktop.
RFC822 e-mail address matcher in JS
function validate_email(email) {
var re = new RegExp(
"^([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c" +
"\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22" +
"\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)(\\x2e" +
"([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e" +
"\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-" +
"\\xff]|\\x5c[\\x00-\\x7f])*\\x22))*\\x40([^\\x00-\\x20\\x22" +
"\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]" +
"+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x5d)" +
"(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40" +
"\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff]|\\x5c" +
"[\\x00-\\x7f])*\\x5d))*$");
return re.test(email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment