我有一个输入,我需要检查它是否只包含字母字符(作为姓名,例如 peter)。这是我的代码:(但它只适用于英文字符)
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
如何为阿拉伯字符创建 regex
?
最佳答案
只需使用 \p{L}
即可匹配来自任何语言的任何类型的字母。
$name = test_input($_POST["name"]);
if (!preg_match("/^[\p{L} ]+$/u",$name)) {
$nameErr = "Only letters and white space allowed";
}
如果不需要,请从字符类中删除空格字符。
关于php - 将输入验证为阿拉伯字符的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31742476/