js 验密码强弱的小例子

时间:2016.04.19 发布人:fgyhgkhdj

js 验密码强弱的小例子

已解决问题

谷歌fgyhgkhdj用户在2016.04.19提交了关于“欧诗漫js 验密码强弱的小例子”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-08-21T04:21:26。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,你无异于雪中送炭,让我感激涕零 !

希望以下的回答,能够帮助你。

第1个回答

用户名:m421457483  

了室顶地体命著可秋页面代码:

复制代码代码如下:
<table>
<tr><td><inputtype="text"id="txtPwd"/></td></tr>
<t格花r><td>
<t额房极立ableid="pwdLever">
<tr>
<td>弱</td>
<td>中</td>
<t祖病效术设晶感粉田下界d>强</td>
</tr>
</table>
</td></tr>
</table>

样式:

复制代码代码如下问答:
<styletype=们钱怕药好急样究老受士"text/css">
#pwdLevertd
{
background-color:Gray;
w决比游字idth:4**x;
t粒脚接便走若ext-align:center;
}
</style>

js代码:

复制代码代码如下:
<scr连叶赵次久皇ipttype="text/j四核条业无待担在社井伤**ascript">
window.onload=f孩小育难新毫一喜载价大unction(){
v组看燃诉重沙artextInput=document.getElementById("txtPwd");
//给密码输入框注册键放开事件
textInput.onkeyup=function(){
varpwdValue=this.value;
var**m=pwdChange(pwdValue);
vartds=document.getElementById(巴殖确有入似厚室收香"pwdLever").吗介职明修观径斤getElementsByTagName("td");
//修改密码颜色
if(**m==0||**m==1){
t商便论者当政持屋系ds[0].style.backgroundColor="red";
tds[1].style.backgroundColor="gray"孔线令误;
t著ds[2].style.backgroundColor="gray";
}
elseif(**m==2){
tds[0].style.backgroundCo沙攻若消沙紧lor="red";
tds[1].style.backgroundColor="red";
tds[2].style.backgroundC态接基小左示曲皇察olor="gray";
}
elseif(**m==3){
tds[0].style.backgroundColor="red";
tds[1].style.backgroundColor="red";
tds[2].style.backgroundColor="red";
}
else{
tds[0].style.backgroundColor="gray";
tds[1].style.backgroundColor="gray";
tds[2].style.backgroundColor="gray";
}
}
}
functionpwdChange(v){
var**m=0;
varreg=/\d/;//如果有数字
if(reg.test(v)){
**m++;
}
reg=/[a-zA-Z]/;//如果有字母
if(reg.test(v)){
**m++;
}
reg=/[^0-9a-zA-Z]/;//如果有特殊字符
if(reg.test(v)){
**m++;
}
if(v.length<6){//如果密码小于6
**m--;
}
return**m;
}
</script>