Nicolas Bouliane

How to validate email addresses in PHP

Posted on

How to validate email addresses in PHP

This regex will match email adresses. However, it’s not bulletproof. Emails such as n@n.n or ____@--... would still pass validation.

/^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/

If you are using PHP, you can also use filter_var() and save yourself some headaches. As illustrated here, it correctly validates most addresses.

filter_var('test@test.com', FILTER_VALIDATE_EMAIL); //Returns true if email is valid, false otherwise