PHP Ramblings

PHP email regex, the way it should be done

posted Aug 17, 2011, 11:44 AM by Zeger Knops

Usually when checking for a valid email address in PHP I use:
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",'bob@alice.com')
A much better approach is:

filter_var( 'bob@alice.com', FILTER_VALIDATE_EMAIL )

More at http://www.php.net/manual/en/function.filter-var.php

1-1 of 1