判断用户名和密码正则表达式
<?php$string[] = 'lewis_0913';$string[] = '刘易斯_0913';$string[] = 'lewis&&12';$string[] = '^&*_123';$string[] = '123刘易斯';$usernamePattern = '/^[_a-zA-Z0-9\x{4e00}-\x{9fa5}]{3,16}$/u';$passwordPattern = '/[\x{4e00}-\x{9fa5}]{3,16}/u';foreach( $string as $element ){preg_match( $usernamePattern , $element , $matches[] );}foreach( $string as $element ){preg_match( $passwordPattern , $element , $matches2[] );}var_dump( $matches );echo '<br>';var_dump( $matches2 );?>
array(5) { [0]=> array(1) { [0]=> string(10) "lewis_0913" } [1]=> array(1) { [0]=> string(14) "刘易斯_0913" } [2]=> array(0) { } [3]=> array(0) { } [4]=> array(1) { [0]=> string(12) "123刘易斯" } } array(5) { [0]=> array(0) { } [1]=> array(1) { [0]=> string(9) "刘易斯" } [2]=> array(0) { } [3]=> array(0) { } [4]=> array(1) { [0]=> string(9) "刘易斯" } }