且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在输入文本字段中只允许阿拉伯字符?

更新时间:2023-02-21 11:25:19

使用 unicode 标志:

Use unicode flag:

$text = "الحمد لله رب العالمين";
echo $is_arabic = preg_match('/\p{Arabic}/u', $text);
                                   here __^

如果你只想匹配阿拉伯语,你应该这样做:

If you want to match only arabic you should do:

echo $is_arabic = preg_match('/^[\s\p{Arabic}]+$/u', $text);