- utf8_decode: documentation ( source)
- preg_match: documentation ( source)
<?php
$re = "/^[a-zA-Z ,.\p{Han}]+$/";
$tests = array(
'Mr Smith',
'Mr. Smith',
'Mr. 123 Smith',
'姓名'
);
foreach ($tests as $test) {
if (preg_match($re, utf8_decode($test)) !== 1) {
echo $test . ' failed' . PHP_EOL;
}
}