Live data from Hacker News

The Correct Way to Validate Email Addresses

hackernoon.com

1–10 of 405 posts

Re: The Correct Way to Validate Email Addresses

#4
post #2

TL;DR the odds that the user entered an incorrect-but-valid address are way higher than that they entered one which will not actually be able to receive mail. Send a validation email.

Also relevant was, "If you have a well laid-out form with a label that says “email”, and the user enters an ‘@’ symbol somewhere, then it’s safe to say they understood that they were supposed to be entering an email address."

In other words, it does make sense to check that they entered an '@' symbol somewhere, since it shows that they understood it was an email field. Any 'validation' beyond that is useless.

Re: The Correct Way to Validate Email Addresses

#6
I first encountered the idea of email validation in Agile Web Development with Ruby on Rails, which I read in middle school. In the book they give an example of validating email addresses to show how you could use regex to validate. I wonder if that contributed to the frustrating problem of developers trying to validate emails and not accepting valid inputs.

Re: The Correct Way to Validate Email Addresses

#7
post #4
post #2

TL;DR the odds that the user entered an incorrect-but-valid address are way higher than that they entered one which will not actually be able to receive mail. Send a validation email.

Also relevant was, "If you have a well laid-out form with a label that says “email”, and the user enters an ‘@’ symbol somewhere, then it’s safe to say they understood that they were supposed to be entering an email address." In other words, it does make sense to check that they entered an '@' symbol somewhere, since it shows that they understood it was an email field. Any 'validation' beyond that is useless.

How about more than one @ sign? Does the email address spec exclude the possibility of more than one @ symbols?

Re: The Correct Way to Validate Email Addresses

#8
As an aside, I received an email from a government department recently that had an '&' character as part of the email address. I didn't think that was valid, but lo and behold, when I checked the specs, it IS indeed a valid character in an email address.

Just goes to show that assumptions are often wrong, and you have to crack open the spec document from time to time... [1]

[1] - https://tools.ietf.org/html/rfc2822

Re: The Correct Way to Validate Email Addresses

#9
There are other situations where you do have to guess whether a string of data is a "real" email address or if it's some garbage data that turns up in information systems. "Validating" email addresses (without emailing somebody) is a real problem. By the way, maximizing the accuracy of such a guess can require going against the standards.
Post reply on HN