Live data from Hacker News

Email address validation: please stop

blog.sinjakli.co.uk

1–10 of 86 posts

Re: Email address validation: please stop

#5
I tend to rely on 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])+)\])

Re: Email address validation: please stop

#6
post #2

I recently changed our email validation: all I do now is check for the existence of an "@".

Then why validate at all? Just send the user an email with an activation link. If it doesn't work and they're still logged into the site (with a limited account), then let them change their email address.

Re: Email address validation: please stop

#9
post #8
post #3

On the other hand, maybe the specification for email addresses is too loose.

Maybe. I all know is that no one should have to write a regexp like this one http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html

the regexp is very impressive, but it's not quite as bad as it would want you to believe. The regexp also matches real names in addresses and lists of addresses.

Usually, in forms, you would ask for the real name and for the email address in separate fields and you wouldn't allow lists to be passed in.

I do agree though: The email address format is (even without the real name part) too complicated to really validate. In my applications, I check if there's an @-sign (I usually need a proper SMTP email address to deliver anyways), but leave the rest to the mail server on send-time, handling the bounces.

Post reply on HN