php郵箱地址Regex驗證,郵箱地址Regex_PHP教程

來源:互聯網
上載者:User

php郵箱地址Regex驗證,郵箱地址Regex


我們最經常遇到的驗證,就是電子郵件地址驗證。網站上常見。各種網頁指令碼也都常用“Regex”(regular expression)對我們輸入的電子郵件地址進行驗證,判斷是否合法。有的還能分解出使用者名稱和網域名稱。現在用PHP語言實現一下電子郵件地址驗證程式,用的是PHPRegex庫。
原始碼如下:

<?php  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 = "您輸入的電子郵件地址合法

\n"; $user_name = preg_replace( $pattern ,"$1", $email_address ); $domain_name = preg_replace( $pattern ,"$2", $email_address ); $reply .= "使用者名稱:".$user_name."
\n"; $reply .= "網域名稱:".$domain_name."
\n\n"; } else { $reply = "您輸入的電子郵件地址不合法"; } }?>電子郵件地址驗證程式

電子郵件地址驗證程式

<?php echo $reply;?>

以上就是為大家分享的php郵箱地址Regex驗證,希望對大家的學習有所協助。

http://www.bkjia.com/PHPjc/1071225.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1071225.htmlTechArticlephp郵箱地址Regex驗證,郵箱地址Regex 我們最經常遇到的驗證,就是電子郵件地址驗證。網站上常見。各種網頁指令碼也都常用“...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.