2

我使用下面的代码有这样的东西:“ محمد125 hasan ”。限制为 3 到 25 个字符。但它不起作用。

(^[ \d\p{Arabic}a-zA-Z0-9 ]{3,25}$)
4

2 回答 2

2

干净利落:

^[\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 上查看演示

于 2016-03-22T14:05:37.850 回答
0

只需将 \w 与u修饰符一起使用,这意味着 unicode

/^[ \d\p\wa-zA-Z0-9 ]{3,25}$/u

https://regex101.com/r/mC5uT3/1

于 2016-03-22T14:03:24.010 回答