Email Address Validation Updated

I've updated the Email Address Validation function posted in June 2004. I've converted it to a PHP5 compatible class, and released it under a New BSD License on Google Code.


In June 2004, I posted an article titled Email Address Validation, which included a function for validating email addresses according to RFC 2822 and related documents. It tested only for technical validity, nothing more.

The post proved to be reasonably popular, generating a lot of comments and additions from other PHP developers. Unfortunately, I was not too hot at keeping up, and many improvments took too long to make it to the posted version of the function.

Why Revisit This?

There is still a need for validation of email addresses according to standards. ICANN's approval of their new gLTD program means that older email validation systems that checked for TLDs of 6 characters or fewer are now effectively broken. Domains, and as a result email validation, will be getting much more complicated.

So What's New?

I've incorporated suggestings from other developers who commented on the original article, and as a result it now validates email addresses much more accurately.

I've converted the function to a pretty basic object, which I hope will make it easier to read, understand, modify and also integrate into other systems. The domain validation could also be stripped out of the class easily for use as a domain name validator.

Next, I've created unit tests (PHPUnit) so the validation can be checked as it is changed. More cases need to be added, but it should cover all the basic items that should be allwed and disallowed. Of course, anyone can run this against their own validator(s) if they need to.

Finally, I've released the code under a New BSD License (similar to GPL but permits commercial use) on Google Code - php-email-address-validation/ - and I hope this allows other developers to add to and improve the existing code (suggestions and improvements can be left here or posted to the Google Group).