Sabri Aziri
Sabri Aziri

Reputation: 4184

php validate if string is alphabetic including cyrillic, greek or any unicode letter

I am trying to validate string is alphabetic including multiple character sets:

function is_string($str){
    return preg_match("/^[a-zA-Z\p{Cyrillic}\p{Cyrillic}]+$/u", $str) ? TRUE : FALSE;
}

but it fails if string contains some other characters of different languages (ç, ë are used in albanian language)

is_string('ç');//false
is_string('ë');//false

Is there any general function or something which will fix this problem for any character set?

Upvotes: 3

Views: 885

Answers (1)

user3942918
user3942918

Reputation: 26375

\p{L}\p{M}* matches any letter including diacritics (if any.)

Upvotes: 4

Related Questions