xxxxxxxxxx
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
//further code if email is valid
} else {
//further code if email is invalid
}
xxxxxxxxxx
<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo " $email_a is valid email.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo " '$email_b' is valid email.";
} else {
echo "$email_b ooops NOT VALID try again";
}
?>
xxxxxxxxxx
<?php
$email = "pattrick@tutorialspoint.com";
// Validate email
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email address");
}
else{
echo("$email is not a valid email address");
}
?>
xxxxxxxxxx
<?php
filter_var('sgamgee@example.com', FILTER_VALIDATE_EMAIL); // Returns "sgamgee@example.com". This is a valid email address.
filter_var('sauron@mordor', FILTER_VALIDATE_EMAIL); // Returns boolean false! This is *not* a valid email address.
?>
xxxxxxxxxx
filter_var('valid@email.com', FILTER_VALIDATE_EMAIL)//true
filter_var('invalid@email', FILTER_VALIDATE_EMAIL)//false