如何在输入文本字段中仅允许使用阿拉伯字符?
问题描述:
我已经在这里搜索过,并且发现了与此帖子相关的类似帖子,但是我还没有找到解决方案.
I already searched here and found similar posts related to this post but i did not find a solution yet .
我尝试过这个:
$text = "الحمد لله رب العالمين hello";
echo $is_arabic = preg_match('/\p{Arabic}/u', $text);
我添加了unicode标志,但是如果我添加了任何英文字符,它将返回true!有什么解决办法吗?
I add the unicode flag but if i add any English characters it is returning true ! any fix for this ?
有想法的人吗?
预先感谢
答
使用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);