Quick links: Source code | Email address validation service
[UPDATE 15 March 2011: see my comment below]
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 firstname.lastname@example.org 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:
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:
the (“wonderful” (!)) world
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.