php - Regex to allow a limited number of UTF characters i.e. allows only 2, 25 utf8 characters -


i need php regular expression should allow characters of languages limit of minimum 2 chars , maximum 25 chars. below code trying.

$post = 'sıhhiye-ankara àl škofja loka long string '; preg_match('/[\p{l}]{2,25}/u', $post); 

the regular expression allowing utf chars correctly limit of 2,28 not working.

thanks, shahid

you can use anchors ^ , $, make sure matching starts @ beginning , ends @ end of string:

preg_match('/^\p{l}{2,25}$/u', $post); 

here demo


Comments