郵箱地址正規表示式驗證

HelloWorld-Q發表於2020-10-22
header ( "Content-Type: text/html; charset=UTF-8" );
  $reply = "";
  if ( isset($_POST["email_address"]) )
  {
    $email_address = $_POST["email_address"];
    $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
    if ( preg_match( $pattern, $email_address ) )
    {
      $reply = "您輸入的電子郵件地址合法<br /><br />\n";
      $user_name = preg_replace( $pattern ,"$1", $email_address );
      $domain_name = preg_replace( $pattern ,"$2", $email_address );
      $reply .= "使用者名稱:".$user_name."<br />\n";
      $reply .= "域名:".$domain_name."<br />\n\n";
    }
    else
    {
      $reply = "您輸入的電子郵件地址不合法";
    }
  }
本作品採用《CC 協議》,轉載必須註明作者和本文連結
有夢想的人睡不著,沒有夢想的人睡不醒。

相關文章