PHP - Stop using RegEx for email validation
Save yourself a lot of time and stress fiddling with RegEx to work with edge cases.
Instead, use PHP's built in filter_var
method like so;
<?php
$email = 'my.email+is-weird@domain-name.com';
if ( filter_var($email, FILTER_VALIDATE_EMAIL) ) {
echo "Valid";
} else {
echo "Invalid";
}
References & Documentation:
http://www.php.net/manual/en/filter.examples.validation.php
http://www.php.net/manual/en/function.filter-var.php
Written by Joel Day
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#