我使用下面的代码有这样的东西:“ محمد125 hasan ”。限制为 3 到 25 个字符。但它不起作用。
(^[ \d\p{Arabic}a-zA-Z0-9 ]{3,25}$)
干净利落:
^[\d\p{L}\h]{3,25}$
# match the start (^), digits or any letter
# and horizontal space three to 25 times
# end of the string/line ($)
在PHP
这将是:
$string = 'محمد125 hasan ';
$regex = '~^[\d\p{L}\h]{3,25}$~';
if (preg_match($regex, $string, $match) {
// do sth. useful here
}
在 regex101.com 上查看演示。