我使用以下代码具有类似以下内容:"محمد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 的演示。
只需将 ''w 与 u
修饰符一起使用,这意味着 unicode
/^[ 'd'p'wa-zA-Z0-9 ]{3,25}$/u
https://regex101.com/r/mC5uT3/1