No comments yet
Dominic Sayers is an independent technology professional with many years experience in the financial services industry. He is currently helping to build an online service for independent investors and entrepreneurs.
Copyright © 2010 Dominic Sayers. Titan Theme by The Theme Foundry.
address, cal henderson, comments, email, ietf, paul gregg, rfc2821, rfc2822, rfc3696, rfc5322, rfc822, smtp, validation
Comments in email addresses
Quick links: Source code | Email address validators head-to-head
I was turning a blind eye to the part of RFC5322 that allows you to put comments within an email address. But Cal H brought it up in an email so I had to bite the bullet.
On reflection I think this was worthwhile. The most common error in email address validators is that they reject valid addresses. This really annoys people who like to put a ‘+’ in their address and find they can’t because registration form won’t allow it.
Why do they like putting a ‘+’ in their address? Well it effectively tags the incoming email for you automatically. Mail sent to first.last+hello@example.com will go to the first.last mailbox, tagged with ‘hello’. GMail will do this for you – try it.
So that’s why I think it’s worth allowing comments. The next GMail might be able to do the same thing or something even more useful with comments:
first.last(notify IM)@example.com
Version 1.6 of my validator now passes all 222 unit tests. So does Cal’s. I see no reason why you wouldn’t use one of these in your project: they are free and they work. Why reinvent the wheel?
RFC nerd notes
Comments can contain folding white space and can be nested. This is the final nail in the coffin for regular expressions that claim to validate email address. Show me a regex that says this is a valid address:
first(Welcome to
the (“wonderful” (!)) world
of email)@example.com
A thank-you also to Paul Gregg who allowed me to add his validator to the head-to-head (and added mine to his page). He also provided some more unit tests.
Quick links: Source code | Email address validators head-to-head
From → Email address validation, Relevant to my work, howto