Created
January 4, 2014 07:26
-
-
Save thalesfsp/8252687 to your computer and use it in GitHub Desktop.
True javascript email regex
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
/** | |
* Validate email function with regualr expression | |
* See http://regex101.com/r/pN0fP5 | |
* If email isn't valid then return false | |
* | |
* @param email | |
* @return Boolean | |
*/ | |
function validateEmail (email) { | |
var emailReg = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); | |
var valid = emailReg.test(email); | |
if (!valid) { | |
return false; | |
} else { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment