PHP preg_match的簡單使用,驗證郵箱地址


 1 <?php
 2     function match_email($email) {
 3         $pattern = "/\w+@(\w|\d)+\.\w{2,3}/i";
 4         preg_match($pattern, $email, $matches);
 5         return $matches;
 6     }
 7     
 8     $email1 = "test@qq.com";
 9     $email2 = "test@163.com";
10     $email3 = "163@qq163.com";
11     $email4 = "test%@q..q.com";
12     var_dump(match_email($email1));
13     var_dump(match_email($email2));
14     var_dump(match_email($email3));
15     var_dump(match_email($email4));
16 ?>

輸出

array(2) { [0]=> string(11) "test@qq.com" [1]=> string(1) "q" } array(2) { [0]=> string(12) "test@163.com" [1]=> string(1) "3" } array(2) { [0]=> string(13) "163@qq163.com" [1]=> string(1) "3" } array(0) { }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM