validate input email php code example
Example 1: how to validate an email field using php
<?php
$email = "[email protected]";
// 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");
}
?>
Example 2: validate correct format email php
$email = $_POST["email"];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}