Reputation: 327
I use below code to have something like this: " محمد125 hasan ". with a limit of being between 3 and 25 characters. but it doesn't work.
(^[ \d\p{Arabic}a-zA-Z0-9 ]{3,25}$)
Upvotes: 2
Views: 800
Reputation: 43169
Plain and simple:
^[\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 ($)
In PHP
this would be:
$string = 'محمد125 hasan ';
$regex = '~^[\d\p{L}\h]{3,25}$~';
if (preg_match($regex, $string, $match) {
// do sth. useful here
}
Upvotes: 2
Reputation: 34152
Just use \w with u
modifier which means unicode
/^[ \d\p\wa-zA-Z0-9 ]{3,25}$/u
https://regex101.com/r/mC5uT3/1
Upvotes: 0