js验证密码强度

<script>
        function isSecurity(v){
                if (v.length < 3){iss.reset();return;}
                var lv = -1;
                if (v.match(/[a-z]/ig)){lv++;}
                if (v.match(/[0-9]/ig)){lv++;}
                if (v.match(/(.[^a-z0-9])/ig)){lv++;}
                if (v.length < 6 && lv > 0){lv--;}
                iss.reset();
                switch(lv)
                {                               
                        case 0:
                                iss.level0();
                                break;
                        case 1:
                                iss.level1();
                                break;
                        case 2:
                                iss.level2();
                                break;
                        default:
                                iss.reset();
                }
        }
        var iss = {
                color:["CC0000","FFCC33","66CC00","CCCCCC"],
                text:["弱","中","强"],
    width:["50","100","150","10"],
                reset:function(){
                        $("B").style.backgroundColor = iss.color[3];
      $("B").style.width = iss.width[3];
                        $("A").innerHTML = "验证试中";

                },
                level0:function(){
                        $("B").style.backgroundColor = iss.color[0];
      $("B").style.width = iss.width[0];
      $("A").innerHTML = "较弱";
                },
                level1:function(){
                        $("B").style.backgroundColor = iss.color[1];
      $("B").style.width = iss.width[1];
                        $("A").innerHTML = "中";                       
                },
                level2:function(){
                        $("B").style.backgroundColor = iss.color[2];
      $("B").style.width = iss.width[2];
                        $("A").innerHTML = "高强";
                       
                }
        }
        var $ = function(v){return document.getElementById(v);}
</script>
<input type=password name=password size=25 maxlength=20 οnkeyup="isSecurity(this.value);">
<font class=red id=A>密码强度</font>
<table  height="8" border="1" align="left" cellpadding="0" cellspacing="0" bordercolor="#EEEEEE" style="border-collapse:collapse;">
  <tr>
    <td bgcolor="#EEEEEE" width="1" align="center" valign="middle" id="B"></td>
  </table> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值