Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preg_match unicode does not work with some languages

With this regular expression can not validate the text in the following languages​​:

/^[\p{L}\p{Nd}-_.]{1,20}$/u

Languages ​​that do not work:

Bengali, Gujarati, Hindi, Marathi, Thai, Tamil, Telugu, Vietnamese

when used with PHP's preg_match.

What am I missing?

like image 675
user2068995 Avatar asked Apr 27 '26 14:04

user2068995


1 Answers

You're using the dash incorrectly. If you want it to match a literal dash character, you need to either escape it (\-) or put it at the end of the character class.

Also, I'm not familiar with those languages, but I guess you might need to account for marks as well:

/^[\p{L}\p{Nd}\p{M}_.-]{1,20}$/u
like image 78
Tim Pietzcker Avatar answered Apr 29 '26 06:04

Tim Pietzcker