如何使电子邮件验证功能与EXTR_PREFIX_SAME一起使用?任何建议将不胜感激。谢谢。
这是PHP文件
<?php
extract($_POST, EXTR_PREFIX_SAME, "post");
// Make variable names correspond to form element names with extract and EXTR_PREFIX_SAME
// response
echo "<h1>Thank you for your interest.</h1>";
echo "<div>Here is a copy of the information you provided:<br/><br/>";
echo "Where did you hear about us: ".$where_hear."<br/>";
// text area
echo "Name: ".$name."<br/>";
echo "Email: ".$email."<br/>";
// email validation function
function valid_email($email) {
$good_email = "/^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/ ";
if (preg_match($good_email, $email)) {
echo $email . " is a valid email address.<br>";
return true;
}
else {
echo $email . " is NOT a valid email address.<br>";
return false;
}
}
//email validation function end
?>
答案 0 :(得分:0)
为什么你不使用:
filter_var($value, FILTER_VALIDATE_EMAIL)
...
我认为这是验证PHP中电子邮件的最佳方式。
if(!filter_var($value, FILTER_VALIDATE_EMAIL)){
echo "Invalid e-mail";
}