基本上我在我的网站上有一个小表单,当我提交它时,我希望php检查电子邮件输入<input type="text" name="destinationMail">
是否匹配正确的电子邮件正则表达式模式,即:[a-Z0-9.]+[@][a-Z]+[.][a-Z]{3}
我知道PHP中有函数检查正确的电子邮件(我认为),但我想使用正则表达式。
谢谢。
基于正则表达式:
$email = "test123@email.com";
$regex = "^[A-z0-9.]+@[A-z]+'.[A-z]{3}+$^";
if (preg_match($regex, $email))
{
echo $email . " = valid.";
} else
{
echo $email . " = invalid";
}
虽然我建议php filter_var
preg_match
会做你需要的。
if(preg_match($regex,$email)){
echo "Email matches regex!";
}