JavaScript+DiV密码安全性验证
一个简单的密码安全性验证的完整代码,如果那位高人有更好的,希望能回复给我:
<!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" >
<head>
<title>密码安全性验证</title>
<script language=javascript>
function hiddenLayer()
{
layer1.style.visibility="hidden";
layer2.style.visibility="hidden";
layer3.style.visibility="hidden";
}
function checkPassWordLevel(o) {
var n=0;
if (/\d/.test(o.value)) n ++; //包含数字
if (/[a-z]/.test(o.value)) n ++; //包含小写字母
if (/[A-Z]/.test(o.value)) n ++; //包含大写字母
if (/\W/.test(o.value)) n ++; //包含其他字符
if (o.value.length<5) n=1; //长度小于5位
if(n==1)
{
layer1.style.visibility="visible";
layer2.style.visibility="hidden";
layer3.style.visibility="hidden";
}
else if(n==2)
{
layer1.style.visibility="hidden";
layer2.style.visibility="visible";
layer3.style.visibility="hidden";
}
else if(n>=3)
{
layer1.style.visibility="hidden";
layer2.style.visibility="hidden";
layer3.style.visibility="visible";
}
}
</script>
</head>
<body onload="hiddenLayer()">
密码:<input id="Password1" type="password" onkeyup="checkPassWordLevel(this)"/><br />
<div id="layer1" style="z-index: 101; left: 57px; width: 150px; position: absolute;
top: 39px; height: 20px; background-color: #ff0000">
<span style="color: #ffffff"><strong> 不安全</strong></span></div>
<div id="layer2" style="z-index: 102; left: 57px; width: 150px; position: absolute;
top: 39px; height: 20px; background-color: #ffcc33">
<span style="color: #ffffff"><strong> 普通</strong></span></div>
<div id="layer3" style="z-index: 102; left: 57px; width: 150px; position: absolute;
top: 39px; height: 20px; background-color: #006600">
<span style="color: #ffffff"><strong> 很安全</strong></span></div>
</body>
</html>