Something I’ve done a hundred thousand times (seriously, I counted) using a handy dandy regular expression in my personal library.This time, for some reason, I decided to take a look at my underlying assumptions.

validating email address form-42

Raise your hand if you know how to validate an email address.

For those of you with your hand in the air, put it down quickly before someone sees you.

It’s an odd sight to see someone sitting alone at the keyboard raising his or her hand. Before yesterday I would have raised my hand (metaphorically) as well.

I needed to validate an email address on the server.

Quoting can be done via the backslash character (what is commonly known as escaping) or via surrounding the local part in double quotes. Quick, run these through your favorite email validation method. For fun, I decided to try and write a regular expression (yes, I know I now have two problems. Most email providers have stricter rules than are required for email addresses.

For example, Yahoo requires that an email start with a letter.There seems to be a standard stricter set of rules most email providers follow, but as far as I can tell it is undocumented.According to section 2.3.10 of RFC 2821 which defines SMTP, the part before the Consequently, and due to a long history of problems when intermediate hosts have attempted to optimize transport by modifying them, the local-part MUST be interpreted and assigned semantics only by the host specified in the domain part of the address.An addr-spec is a specific Internet identifier that contains a locally interpreted string followed by the at-sign character (“@”, ASCII value 64) followed by an Internet domain.The locally interpreted string is either a quoted-string or a dot-atom.Not only that, but it’s also valid (though not recommended and very uncommon) to have quoted local parts which allow pretty much any character. (The part in bold is the Before you call me a completely anal nitpicky numnut (you might be right, but wait anyways), I don’t think this level of detail in email validation is absolutely necessary.