Here I have 2 email validation regexps, which one is better and why?

new RegExp("^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,}$", "i");

new RegExp("^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})*$", "");
  • 1
    \$\begingroup\$ Related Email validation using JavaScript \$\endgroup\$
    – Rubén
    Commented Jul 13, 2020 at 23:30
  • \$\begingroup\$ Assuming this is for associating an email to a person, even if the regexp was perfect, that tells you almost nothing about the validity of that person's email. There is only really one way to check a person's email, and that's to email them. \$\endgroup\$
    – Neil
    Commented Jul 14, 2020 at 0:32

2 Answers 2


There probably is no 'good' regexp to validate an email id. The Internet Standard RFC has classified a 500-character long RegExp which according to them is the standard way to validate an email-id. Well, it does work, but it is so messy and almost impossible for most of us to understand.


If you have understood it, then, you need not read further. But if you haven't, go on.

This page gives a decent info on how to validate an email id using regexp.

I use this one


This works fine, atleast for me, but it fails to validate emails on .museum domain or any other domain longer than 4-characters.

Coming to your patterns, both of them are almost same except the fact that the first one uses i modifier and it allows 2 or more than 2 characters as TLD. Hope it helps.

  • \$\begingroup\$ The other problem with the RFCs is that they only care about syntactically valid email addresses. [email protected] may be syntactically valid, but it's probably not what the user intended to type, even if the .con domain exists. \$\endgroup\$
    – Brian
    Commented Dec 26, 2012 at 18:22
  • \$\begingroup\$ Your suggestion breaks on '@example.com and *@example.com both of which are entirely valid. \$\endgroup\$
    – J99
    Commented Jul 23, 2013 at 12:39
  • \$\begingroup\$ IP addresses are valid server destinations, too. \$\endgroup\$ Commented Jul 23, 2013 at 17:39

Both are totally broken as they both fail to accept the + character in the local part and one of them requires more than one digit for the domain name. Single-digit domain names are perfectly fine in some TLDs (such as .de).

If you really need more validation than a simple "has the *@*.* format" check, you need to read this answer on Stack Overflow: Using a regular expression to validate an email address


Not the answer you're looking for? Browse other questions tagged or ask your own question.