我正在尝试使用php找到正确的正则表达式以检查伪。它应该在4到64个字符之间,具有字母数字字符(区分大小写)和下划线。我试过这些:
preg_match ( "/^([[[:alnum:]]_]){4, 64}$/", $pseudo )
preg_match ( "/^([a-zA-Z0-9_]){4, 64}$/", $pseudo )
preg_match ( "/^[[[:alnum:]]_]{4, 64}$/", $pseudo )
preg_match ( "/^[a-zA-Z0-9_]{4, 64}$/", $pseudo )
preg_match ( "/^([[[:alnum:]]_]){4,64}$/", $pseudo )
preg_match ( "/^([a-zA-Z0-9_]){4,64}$/", $pseudo )
preg_match ( "/^[[[:alnum:]]_]{4,64}$/", $pseudo )
preg_match ( "/^[a-zA-Z0-9_]{4,64}$/", $pseudo )
preg_match ( "#^([[[:alnum:]]_]){4, 64}$#", $pseudo )
preg_match ( "#^([a-zA-Z0-9_]){4, 64}$#", $pseudo )
preg_match ( "#^[[[:alnum:]]_]{4, 64}$#", $pseudo )
preg_match ( "#^[a-zA-Z0-9_]{4, 64}$#", $pseudo )
preg_match ( "#^([[[:alnum:]]_]){4,64}$#", $pseudo )
preg_match ( "#^([a-zA-Z0-9_]){4,64}$#", $pseudo )
preg_match ( "#^[[[:alnum:]]_]{4,64}$#", $pseudo )
preg_match ( "#^[a-zA-Z0-9_]{4,64}$#", $pseudo )
...
还有更多,但没有人工作,我找不到原因。
编辑:我的功能是这样的:function pseudoIsAllowed($pseudo) {
$res = true;
echo "$pseudo\n";
if (! preg_match ( "/^[[[:alnum:]]_]{4,64}$/", $pseudo ))
$res = false;
if ($res)
echo "$pseudo is allowed.\n";
else
echo "$pseudo is NOT allowed.\n";
return $res;
}
答案 0 :(得分:0)
似乎/ ^ [[:alnum:] _] {4,64} $ /有效。也许这是一个缓存问题或类似的东西。谢谢大家。