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