1

如何使电子邮件验证功能与 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

    ?>
4

1 回答 1

0

为什么你不使用:

filter_var($value, FILTER_VALIDATE_EMAIL)

??

我认为这是在 PHP 中验证电子邮件的最佳方式。

if(!filter_var($value, FILTER_VALIDATE_EMAIL)){
   echo "Invalid e-mail";
}
于 2013-05-03T16:39:56.143 回答