- Pattern in the input field
- Input field type email
- jQuery email:true
- PHP : filter_var($email, FILTER_VALIDATE_EMAIL)
function validate_email($email) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$domain = explode("@", $email);
$domain = end($domain); // Extract the domain
// List of popular email domains
$popularDomains = array("gmail.com", "yahoo.com", "outlook.com", "hotmail.com");
if (checkdnsrr($domain, "MX")) {
if (in_array($domain, $popularDomains)) {
return true; // Valid email address with a popular domain
} else {
return false; // Valid email address, but not a popular domain
}
} else {
return false; // Invalid domain
}
} else {
return false; // Invalid email format
}
}
?>
Calling part of the function
$emailToValidate = "bijay.to.access@gg.com";
if (validate_email($emailToValidate)) {
echo "Valid email address";
} else {
echo "Invalid email address for our requirement";
}
?>