0
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"));
DarkLightA
  • 14,980
  • 18
  • 49
  • 57
  • 1
    Doesn't have to be in JS. @DarkLight What is the problem, what doesn't work? – Pekka Dec 27 '10 at 21:30
  • 1
    possible 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 Answers2

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.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469
  • 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