如何在输入文本字段中仅允许使用阿拉伯字符? [英] How can i allow only arabic characters in input text field?

查看:89
本文介绍了如何在输入文本字段中仅允许使用阿拉伯字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里搜索过,并且发现了与此帖子相关的类似帖子,但是我还没有找到解决方案.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆