正则网站:http://tools.jb51.net/regex/create_reg 字符判断汉字:/^[ _-a-zA-Z0-9\x{4e00}-\x{9fa5}]+$/u 字节判断汉字:preg_match('/[\x80-\xff]{6,30}/', $str); 判断emoj表情: public static function emojCheck($str) { if(preg_match('/[\xf0-\xf7]/', $str)){ return true; } return false; }
//验证账号 if (preg_match("/^[a-zA-Z0-9\x{4e00}-\x{9fa5}]+$/u",$password)) { return json_encode([ 'status' => 0, 'msg' => '姓名由字母,汉字组成' ]); } //验证密码 if(!preg_match('/^[a-zA-Z0-9_-]{6,}$/',$password)){ return json_encode([ 'status' => 0, 'msg' => '密码由至少6位数字,字母,_,-组成' ]); }
}