复制番号代番号次のように:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<頭>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<タイトル>
密暗号强度检测
</タイトル>
<style type="text/css">
body{font:12px/1.5 Arial;} input{float:left;font-size:12px;width:150px;font-family:arial;border:1px
実線 #ccc;padding:3px;} input.correct{border:1px 実線緑;} input.error{border:1px
赤一色;} #tips{float:left;margin:2px 0 0 20px;} #tips span{float:left;width:50px;height:20px;color:#fff;overflow:hidden;background:#ccc;margin -right:2px;line-height:20px;text-align:center;}
#tips.s1 .active{background:#f30;} #tips.s2 .active{background:#fc0;} #tips.s3
.active{background:#cc0;} #tips.s4 .active{background:#090;}
</スタイル>
<script type="text/javascript">
window.onload = function() {
var oTips = document.getElementById("ヒント");
var oInput = document.getElementsByTagName("input")[0];
var aSpan = oTips.getElementsByTagName("スパン");
var aStr = ["弱", "中", "强", "非常好"];
変数 i = 0;
oInput.onkeyup = oInput.onfocus = oInput.onblur = function() {
var インデックス = checkStrong(this.value);
this.className = インデックス ? "正しい": "エラー";
oTips.className = "s" + インデックス;
for (i = 0; i < aSpan.length; i++) aSpan[i].className = aSpan[i].innerHTML = "";
インデックス && (aSpan[インデックス - 1].className = "アクティブ", aSpan[インデックス - 1].innerHTML = aStr[インデックス - 1])
}
};
/** 强度规则
+ -------------------------------------------------- ------ +
1) 6 文字未満の任意の文字の組み合わせ、弱; 任意の文字数の同じ種類の文字の組み合わせ、弱;
2) 任意の文字数の 2 つの文字符集合、中;
3) 12 桁の文字数以下の 3 種類または 4 種類の文字組み合わせ、强;
4) 12 桁の文字数以上の 3 種類または 4 種類の文字の組み合わせ。
+ -------------------------------------------------- ------ +
**/
//检测密码强度
関数 checkStrong(sValue) {
var モード = 0;
if (sValue.length < 6) はモードを返します。
if (//d/.test(sValue)) モード++; // 数字
if (/[az]/.test(sValue)) モード++; //小写
if (/[AZ]/.test(sValue)) モード++; //大写
if (//W/.test(sValue)) モード++; //特殊文字
スイッチ (モード) {
ケース1:
1を返します。
壊す;
ケース 2:
2を返します。
ケース 3:
ケース4:
sValue.length < 12 を返しますか? 3:4
壊す;
}
}
</script>
</head>
<本文>
<input type="password" value="" maxlength="16" />
<div id="ヒント">
<スパン></スパン>
<スパン></スパン>
<スパン></スパン>
<スパン></スパン>
</div>
</body>
</html>