匹配账号字母数字下划线及中文(PHP)

//匹配账号字母数字下划线及中文
    protected function match($data){
        //判断长度
        $strln = mb_strlen($data);
        $match = "/^[\x{4e00}-\x{9fa5}_a-zA-Z0-9]+$/u";
        if (preg_match_all($match,$data) && $strln >= 2 &&$strln <= 8 ){
            return true;
        }else{
            return false;
        }
    }

/*
"/^([\p{Han}\p{P}A-Za-z0-9])$/u"
其中
\p{Han}表示utf-8编码中的所有中文字符,
\p{P}表示中英文标点,
A-Z表示大写字母,
a-z表示小写英文字母,
0-9表示数字,
*表示>=0,
/u 表示按unicode(utf-8)匹配(主要针对多字节比如汉字)
*/

猜你喜欢

转载自blog.csdn.net/weixin_43507521/article/details/85014221
今日推荐