如何在输入文本字段中只允许阿拉伯字符? [英] How can i allow only arabic characters in input text field?
本文介绍了如何在输入文本字段中只允许阿拉伯字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在这里搜索并找到了与此帖子相关的类似帖子,但我还没有找到解决方案.
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);
这篇关于如何在输入文本字段中只允许阿拉伯字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文