Created
January 25, 2012 07:37
-
-
Save KrofDrakula/1675236 to your computer and use it in GitHub Desktop.
Email validation? Seriously?
This file contains hidden or 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
| // | |
| // Email address must be of form [email protected] ... in other words: | |
| // * there must be at least one character before the @ | |
| // * there must be at least one character before and after the . | |
| // * the characters @ and . are both required | |
| function isValidEmail(s) | |
| { | |
| if (isEmpty(s)) return false; | |
| // is s whitespace? | |
| if (isWhitespace(s)) return false; | |
| // there must be >= 1 character before @, so we | |
| // start looking at character position 1 | |
| // (i.e. second character) | |
| var i = 1; | |
| var sLength = s.length; | |
| // look for @ | |
| while ((i < sLength) && (s.charAt(i) != "@")) | |
| { i++ | |
| } | |
| if ((i >= sLength) || (s.charAt(i) != "@")) return false; | |
| else i += 2; | |
| // look for . | |
| while ((i < sLength) && (s.charAt(i) != ".")) | |
| { i++ | |
| } | |
| // there must be at least one character after the . | |
| if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false; | |
| else return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment