Is this email regex valid addresses?

I tried to create a regex that catches all RFC-valid addresses, but it's okay if false positives show up (although hopefully not many). This is so, I got to this:

/^\b\S+@\S+\.[^\s@]{2,}\b$/

      

Is there any RFC valid address that doesn't match this expression, or do you have any suggestions for improving it? I don't mind false positives, but I would be glad if you could show me a few too.

+2


a source to share


5 answers


Email addresses can contain nested comments, which spoils most regular expressions. This is a valid email address:

test(Oh (noes, an @) "sign")@(Here comes the domain)domain.com(TLD is com!!)

      



Even without comments, the local part may contain quoted lines, which may contain spaces. The best approach I've found is search @

. It is necessary. So I would use

/.+@.+/

      

+3


a source


Send a message:

Using a regular expression to validate an email address

There is also this one:



http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html

Nothing like a 6000+ character regex!

+5


a source


"foo bar"@example.com

      

The local part can contain spaces (they must be specified, but they are valid).

+3


a source


name@[1.2.3.4]

      

does not match, but valid. A good list of valid / invalid email addresses for testing can be found here .

+1


a source


Try regexbuddy for checking reqular expressions. Another user-friendly site I use regexplib a lot

0


a source







All Articles