by strictnein · 10y ago · 0 comments
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).
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.
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?
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].
(rest of the page is filled with line noise)
LOL
^(?("")(""[^""]+?""@)|(([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