//密码种类
//1.小写字母
//2.大写字母
//3.数字
//4.特殊符号
//弱 1
//中 2
//强 3 或 4
//长度 6~16个字符,区分大小写
//1.长度判断 $pwd_len = strlen($password); if ($pwd_len > 16 || $pwd_len < 6) { echo "<script>alert('密码长度应为6~16个字符');history.back();</script>"; exit; } //2.密码强度 //1) 是否包含小写字母 $pattern = '/[a-z]+/'; $res = preg_match($pattern, $password); //2) 是否包含大写字母 $pattern = '/[A-Z]+/'; $res2 = preg_match($pattern, $password); //3) 是否包含数字 $pattern = '/\d+/'; $res3 = preg_match($pattern, $password); //4) 是否包含特殊符号 $pattern = '/[\!\@\#\$\%\^\&\*\(\)\_\+\-\=\;\:\"\'\|\\\<\>\?\/\.\,\`\~]+/'; $res4 = preg_match($pattern, $password); $sum = $res + $res2 + $res3 + $res4; if ($num == 1) { //弱 echo "<script>alert('密码弱');history.back();</script>"; exit; } elseif ($num == 2) { //中等 echo "<script>alert('密码中等');history.back();</script>"; exit; } elseif ($num >= 3) { //强 echo "<script>alert('密码强');history.back();</script>"; exit; }