How to validate email addresses in PHP
RT @thibauld How to validate email addresses in PHPI guess that every PHP developer out there already had to cope with email validation in PHP. I personally used to think it was not completely straight forward.
Indeed, when you google the subject you quickly find this article with a completely misguiding title: "Validate an Email Address with PHP, the Right Way". Do not use the regexp proposed in this article outdated article. Not only because ereg() has been deprecated and replaced by preg_match() in latest PHP version (5.3 actually), but also because there is much simpler since PHP 5.2.
Check this out:
function is_email_valid($email) {
return filter_var($email,FILTER_VALIDATE_EMAIL)!==false;
}
Now, that's straight forward, isn't it? Here's filter_var() documentation if you want to find out more.