求一个密码正则要来验证用户输入的密码是否合法的。要求我想不能输入中文和空格就可以了,密码长度是6-15个字符。function is_password($str){
return preg_match("[\w\d]",$str);
}可惜return preg_match("[\w\d]",$str);这个正则我写了n多都不正确。。痛哭啊。大家帮忙好吗
return preg_match("[\w\d]",$str);
}可惜return preg_match("[\w\d]",$str);这个正则我写了n多都不正确。。痛哭啊。大家帮忙好吗
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "中文字符串";
} else {
echo "非中文字串";
}但要注意编码的问题,如果中文是utf8编码,你需要加上模式修正符 u
function is_safe($str){
return !preg_match('/[\x80-\xff]|[\s]/', $str); }但是没有限制6-15个字符啊