4 ms·
I tend to rely on http://www.regular-expressions.info/email.html http://www.regular-expressions.info/email.html when coming to validate an email address. I do
by glenjamin 16y ago
I tend to rely on http://www.regular-expressions.info/email.html http://www.regular-expressions.info/email.html when coming to validate an email address.
I do often fall into the trap of trusting the framework's built-in email validation to be correct.
Apparently, this is the regex to match RFC2822
(?:[a-z0-9!#$%&'+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'+/=?^_`{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:[a-z0-9](?:[a-z0-9-][a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-][a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
- retube 16y agoThe problem with matching against the fully fledged RFC compliant regex is that not all email addresses are RFC compliant. As I indicated in my comment above, I've abondoned trying to "correctly" or "completely" validate email addresses. There's onyl one thing certain in an email address: it contains the "@" character.
- metageek 16y agoCam you give an example of a noncompliant address that actually works?
- nourishingvoid 16y agoOne cellular phone company in Japan used to allow people to register e-mail addresses with two periods in a row before the @ character. I have seen some addresses like this in the wild, but the decision to mark these as valid or not for an app depends on the domain you're working in. At my old job making web apps for Japanese companies, programmers would usually allow these types of addresses if we were making a mobile site.
- retube 16y agoHere's an example. I've stumbled across others in the past. http://www.reddit.com/r/programming/comments/fl6i0/email_address_validation_please_stop/c1gr1cg http://www.reddit.com/r/programming/comments/fl6i0/email_add...
- gawker 16y agoThanks! You learn something new from Hacker News everyday. Never thought it'd be such a long regex for emails though. I just got really confused trying to parse that in my head.