这是我的代码(来自submit.php)抛出错误:
$email_from = $_POST['email']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
我知道我需要使用preg_match,但我不知道如何实现它。我已经阅读了文档,但我仍然没有得到它。谢谢!
答案 0 :(得分:-1)
删除此
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
eregi($email_exp,$email_from)
并使用
$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
preg_match($email_exp, $email_from)
答案 1 :(得分:-1)
$email_exp = "/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i";
if(preg_match($email_exp,$email_from) != 1) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
实际上,它与eregi非常简单且非常相似。