这个问题是错的,。裁判官实际上是为我想要的。在regex签入源代码之前,我错过了一个"trim()“。
原题:
我不知道是怎么回事。这个正则表达式在汉字之间不允许空白,但是如果你在前面放一个空格,它就会通过。
if(preg_match('/^[\x{4e00}-\x{9fa5}A-Za-z]{1,7}$/u',$username)){正如你所看到的,我想要中文,英文字母,下划线,没有别的。
发布于 2014-01-23 09:57:07
试试这个正则表达式:
/^[\x{4e00}-\x{9fa5}a-z _]{1,7}$/ui样本代码
<?php
// Since PHP doesn't support Unicode escape sequence, so I use json_decode here for typing random chinese chars
$username = json_decode('" \u4e00 \u4e01f_o"');
echo preg_match('/^[\x{4e00}-\x{9fa5}a-z _]{1,7}$/ui',$username); // ouputs 1
?>演示
http://phpfiddle.org/lite/code/c5t-zr2
https://stackoverflow.com/questions/21299021
复制相似问题