validate if UTF-8 string is alphabetic

662 Views Asked by At

I have some string:

$str = 'Xin chào';
$str2 = 'Xin chào 1';

In order to check if these two string variables is alphabetic, I've tried with ctype_alpha. However, both of ctype_alpha($str) and ctype_alpha($str2) are falsy.

Is there any other method that similars to ctype_alpha and working great with UTF-8?

1

There are 1 best solutions below

1
On

this should work for you

preg_match('/^\p{L}[\p{L} _.-]+$/u', $str);

For more Information take a look at http://php.net/manual/en/regexp.reference.unicode.php