现在不用使用正则表达式,你可以简单地使用PHP的
strstr函数
$email = "xyz@xyz.com";
$email2 = "xyz@xyz.net";
$valid_domain = "@xyz.com";
function checkValidDomain($email, $valid_domain){
if(!filter_var($email,FILTER_VALIDATE_EMAIL) !== false){
if(strstr($email,"@") == $valid_domain){
return "Valid";
}else{
return "Invalid";
}
}else{
return "Invalid Email";
}
}
echo checkValidDomain($email, $valid_domain);// Valid
echo checkValidDomain($email2, $valid_domain);// Invalid