Last active
December 25, 2015 14:09
-
-
Save vnykmshr/6988750 to your computer and use it in GitHub Desktop.
Simple Email Validations
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
/** | |
* Simple email validation | |
* ensures at least one `@` sign, at least one char in local part, | |
* at least one `.` in domain part and is at least one char long | |
*/ | |
isEmail: function (em) { | |
em = em || ''; | |
var indx = em.lastIndexOf('@'); | |
return indx > 0 && (em.lastIndexOf('.') > indx) && (em.length - indx > 1); | |
} | |
module.exports = isEmail; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, your regex solution will work, and I would prefer applying it in forms to validate email addresses. I have written the simple validation routine just to avoid the most blatant ones.