用于检测连续数字的正则表达式 - 不适用于非英语输入

She*_*uzz 3 php regex unicode multibyte preg-match

大家好我有这个代码检查5个或更多连续数字:

if (preg_match("/\d{5}/", $input, $matches) > 0)
return true;
Run Code Online (Sandbox Code Playgroud)

它适用于英语输入,但当输入字符串包含阿拉伯语/多字节字符时它会跳闸 - 有时即使输入文本中没有数字,它也会返回true.

有任何想法吗 ?

Den*_*sky 6

您似乎正在使用PHP.

做这个:

if (preg_match("/\d{5}/u", $input, $matches) > 0)
return true;
Run Code Online (Sandbox Code Playgroud)

请注意表达式末尾的"u"修饰符.它告诉preg_*使用unicode模式进行匹配.