I see a lot of PHP code that uses regex’s to validate emails. PHP has a built in function, filter_var, that validates a variable with your choice of a bunch of different filters. So instead of a regex, you could use:

filter_var($email, FILTER_VALIDATE_EMAIL)

There are known issues with this method if you’re using PHP 5.2.x version less than 5.2.14 or a 5.3.x version less than 5.3.3, but as long as you have something greater than that (which hopefully most people do by now) you’re good!

blog comments powered by Disqus