\p{Cyrillic}匹配西里尔字符(您可以使用阿拉伯语,希腊语等其他字母表)
\d 匹配数字
\s 匹配空白字符
\- 匹配破折号
<?php
header('Content-Type: text/html; charset=utf-8');
$pattern = "/^[\p{Cyrillic}\d\s\-]+$/u";
$subjects = array(12, "ab", "??", '--', '__');
foreach($subjects as $subject){
$match = (bool) preg_match($pattern, $subject);
if($match)
echo "$subject matches the testing pattern<br />";
else
echo "$subject does not match the testing pattern<br />";
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
602 次 |
| 最近记录: |