在 ctype_alnum 中使用阿拉伯字符 [英] Using Arabic characters with ctype_alnum

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

问题描述

我需要在我的网站上允许阿拉伯用户名,该用户名已经在使用 ctype_alnum 来验证 username 字段.当我尝试使用阿拉伯语用户名时,会返回验证错误消息.ctype_alnum 不能将阿拉伯字符识别为字母和数字.我该如何解决这个问题?

I need to allow Arabic usernames on my website which is already using ctype_alnum to validate the username field. When I try to use Arabic usernames, the validation error message is returned. ctype_alnum does not recognize arabic characters as letters and numbers. How can i work around this ?

推荐答案

您可以使用此正则表达式查找所有阿拉伯字符:

You can find all Arabic Characters by using this Regex:

preg_match("/^[a-zA-Z\p{Cyrillic}0-9\s\-]+$/u", $string);

如果匹配的长度等于用户名长度,则它是一个阿拉伯用户名.

If the matched length equals the username length it is an arabic username.

这篇关于在 ctype_alnum 中使用阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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