Validate email address in PHP
Posted: 11 Jan 2015, 09:34
What is the best way to validate an email address in PHP?
I currently use preg_match() with a RegExp:
Is there a better /simpler method?
I currently use preg_match() with a RegExp:
Code: Select all
$email = 'some_name@domain.com';
if(preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $email)) {
echo 'valid email';
}
else {
echo 'not valid email';
}