Created
January 26, 2012 15:07
-
-
Save jzazove/1683176 to your computer and use it in GitHub Desktop.
Validating Email Addresses
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
function validateEmailAddress(s) { | |
var atSym = "@", dot = "."; | |
if (s.indexOf(atSym) === -1 || s.indexOf(" ") !== -1 || s.indexOf(atSym) > s.lastIndexOf(dot) || s.length - s.lastIndexOf(atSym) < 3 || s.lastIndexOf(atSym) + 1 === s.lastIndexOf(dot) || s.length - s.lastIndexOf(dot) <== 2 ) return false; | |
else return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A nice trick: the structure
Can be improved to:
Or, if you really want to ensure that the type returned is a boolean, then you can use: