Email address validation 1.2

Quick links: Source codeEmail address validators head-to-head

I had some very helpful input from Cal Henderson on interpreting RFC 2822. I’ve included his latest validator in my head-to-head comparison and updated the test suite to reflect the consensus from our discussion.

I’ve also updated my own routine so that it still passes all the tests, of which there are now 158. As always, the full analysis is on my website and the latest version of the source code will always be in Google Code.

I would really appreciate it if you find a valid address that fails my validator, or an invalid one that passes, if you would get in touch with me and let me know.

Here are the latest scores:

Dominic Sayers: 100% validated correctly
Simon Slick: 91%
Cal Henderson: 84%
Phil Haack: 80%
Dave Child: 79%

I know Cal is working on IPv6 validation so this may change soon.

RFC nerd notes

There are two principle changes in this version.

Firstly, I now accept Dave Child and Cal Henderson’s opinion that a backslash can escape anything in a quoted string local element. However, it must escape something – it can’t be at the end of the string.

Secondly, if the string is not quoted then the local element must be a vanilla atom. You can’t escape individual characters unless the element is surrounded by double quotes.

By “local element” I mean a single component of a dot-delimited local part.

I’ve extracted the raw specification of a valid email address in BNF (Backus-Naur form) from RFC 5322 and put it here: The BNF from RFC 5322 defining parts of a valid email address. If you try to follow this in the RFC you end up going backwards and forwards and getting confused – it’s much easier to understand in the way I’ve laid it out.

Quick links: Source codeEmail address validators head-to-head


0 Responses to “Email address validation 1.2”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: