email validator php code example
Example 1: php filter validate email
<?php
$email_a = '[email protected]';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "L'adresse email '$email_a' est considérée comme valide.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "L'adresse email '$email_b' est considérée comme valide.";
} else {
echo "L'adresse email '$email_b' est considérée comme invalide.";
}
?>
Example 2: valide email php
$email = "[email protected]";
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Email invalide";
}
Example 3: how to validate an email field using php
<?php
$email = "[email protected]";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email address");
}
else{
echo("$email is not a valid email address");
}
?>