Skip to content

Instantly share code, notes, and snippets.

@charlee
Created March 9, 2013 06:27
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 charlee/5123109 to your computer and use it in GitHub Desktop.
Save charlee/5123109 to your computer and use it in GitHub Desktop.
E-mail address validator
var emailValidator = function(s) {
s = $.trim(s);
var name, addr, p = s.indexOf('<');
if (p >= 0 && s.charAt(s.length - 1) == '>') {
name = $.trim(s.substring(0, p));
addr = s.substring(p+1, s.length - 1);
} else {
addr = s;
}
if (name) {
// check quote
if (!name.match(/^(["'])[^"']+\1$|^[^"']+$/)) return false;
}
return !!addr.match(/^[-0-9A-Za-z!#$%&'*+\/=?^_`{|}~.]+@[-0-9A-Za-z!#$%&'*+\/=?^_`{|}~.]+/);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment