本文介绍了在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中使用阿拉伯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:21