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 = "[email protected]";
 9     $email2 = "[email protected]";
10     $email3 = "[email protected]";
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) "[email protected]" [1]=> string(1) "q" } array(2) { [0]=> string(12) "[email protected]" [1]=> string(1) "3" } array(2) { [0]=> string(13) "[email protected]" [1]=> string(1) "3" } array(0) { }

你可能感兴趣的:(match)