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})*$", "");
|
Here I have 2 email validation regexps, which one is better and why?
|
|||
|
|
|
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 Hope it helps. |
|||
|
|
Both are totally broken as they both fail to accept the If you really need more validation than a simple "has the |
|||
|
|