var regex = /^[a-z\-A-Z_0-9]{1,}\u0040[_\-0-9a-zA-Z]{1,65}\.[a-zA-Z]{2,}$/;
document.write(regex.check("hi@email.com"));
Asked
Active
Viewed 87 times
0

DarkLightA
- 14,980
- 18
- 49
- 57
-
1Doesn't have to be in JS. @DarkLight What is the problem, what doesn't work? – Pekka Dec 27 '10 at 21:30
-
1possible duplicate of [What is the best regular expression for validating email addresses?](http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses) – phihag Dec 27 '10 at 21:33
-
That regex will break for a good amount of email addresses, better to find one that is already written. – epascarello Dec 27 '10 at 21:39
-
There's no "check()" method for RegExp instances, at least not in all browsers. – Pointy Dec 27 '10 at 21:40
2 Answers
4
Your code doesn't output anything, becase the check method doesn't exist in RegExp. You should use RegExp.test method

Rafael
- 18,349
- 5
- 58
- 67
3
.{0,0}
does not match anything (i.e. you probably want to start with ^
and end with $
). And you do not allow jon.bob.smith@my.domain.museum
. You should probably read the stackoverflow question about the best email regex.
-
to confirm this you can plug the regex in at regexpal.com and play around with the results. – Bobby Dec 27 '10 at 21:34