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) { }

posted on 2012-08-11 18:25  ZimZz  阅读(3793)  评论(0编辑  收藏  举报