1 <html> 2 <body> 3 <?php 4 $email_pattern = '/\w{6,16}@\w{1,}\.\w{2,3}/i'; 5 $email_valid = 'test_123@126.net'; 6 $email_invalid = 'test@test%@111@com'; 7 $matches = array(); 8 9 preg_match($email_pattern, $email_valid, $matches[]); 10 preg_match($email_pattern, $email_invalid, $matches[]); 11 12 var_dump($matches); 13 ?> 14 </body> 15 </html>
页面输出
array(2) { [0]=> array(1) { [0]=> string(16) "test_123@126.net" } [1]=> array(0) { } }