Created
March 9, 2013 06:27
-
-
Save charlee/5123109 to your computer and use it in GitHub Desktop.
E-mail address validator
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
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