Validating an email address

6854933580_2c8b688306_z

A complex regex validation on the email address doesn’t introduce an additional solution, it introduces an additional problem. From this day forward, you will no longer squander your time trying to work out the perfect regex to validate email addresses.Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).Would you like to answer one of these unanswered questions instead?Here’s a fairly common code sample from Rails Applications with some sort of authentication system: If you’re experienced at Regex, this seems simple. Sections 3.2.4 and 3.4.1 of the RFC go into the requirements on how an email address needs to be formatted and, well, there’s not much you can’t do in your email address when quotes or backslashes are involved.

validating an email address-17validating an email address-72validating an email address-23validating an email address-61

But keep in mind that one should not rely only upon Java Script validation. This should be validated on the server side as well. They can get ridiculously convoluted as in the case above and, according to the specification, are often too strict anyway. If you actually check the Google query I linked above, people have been writing (or trying to write) RFC-compliant regular expressions to parse email addresses for years.You will also never again run the risk of rejecting what is, in fact, a strange, valid email address.The trick is to first define what we mean by ‘valid’.Let’s imagine that my email address is [email protected]

You must have an account to comment. Please register or login here!