Anything else is going to give you a false negative sooner or later. Yeah, you can spend hours framing a complicated expression that carefully tests for exactly what the current bucket of RFCs specify, but you're guaranteed to run into an MTA somewhere that disagrees with you, and you can argue until the cows come home that you're right and they're wrong, but it's still you that's going to have to change to accommodate them in the end.
Validating emails with regexes is one of those things that seems like it should be fairly straightforward, but thanks to the language in the RFC it is actually a nightmare of rabbit holes filled with landmines.
http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html
I don't know about unicode, but I do note it says it doesn't handle comments (because, apparently, they can be nested - and perl's REs lack recursion).
(rest of the page is filled with line noise)
LOL
Really. Email addresses should have never been allowed to have comments.
Since every new RFC maintains compatibility with this one, we'll probably be stuck with these poor choices for decades.
I guess this is what you're referring to: James Doe <jdoe@a.com>
The email - which is inside the <> - should be parsed correctly, while the rest should be treated as a "comment" [1].
Stuff like:
* comments are allowed with parentheses at either end of the local-part; e.g. john.smith(comment)@example.com and (comment)john.smith@example.com are both equivalent to john.smith@example.com. [1]
* Also have a look at quotes
At first I thought you were a bot. Then that your English was not very good.
Looking at your history clearly both are false.
What did you mean?
Thank you!
* "Abc\@def"@example.com
* "Fred Bloggs"@example.com
* "Joe\\Blow"@example.com
* "Abc@def"@example.com
* customer/department=shipping@example.com
* $A12345@example.com
* !def!xyz%abc@example.com
* _somename@example.com
http://haacked.com/archive/2007/08/21/i-knew-how-to-validate...Have further RFCs not deprecated most of the braindamage from 822? If not, why? Are there really people who are still trying to use such horrible abominations for their email address?
^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$
This and other email validation here: https://github.com/neosmart/web/blob/master/Web%20Toolkit/Em...In any case, it probably won't be too long before we get emoji TLDs, or UTF8 flags to replace the country-code :-D