密码强度

<!DOCTYPE html>

<html lang="en">

 

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>密码强度</title>

    <style>

        body {

            background-color: #ccc;

        }

 

        label {

            width: 40px;

            display: inline-block;

        }

        

 

        .continer {

            margin: 100px auto;

            width: 400px;

            padding: 50px;

            line-height: 40px;

            border: 1px solid #999;

            background-color: #efefef;

        }

 

       

        .strengthLv0 {

            height: 6px;

            width: 120px;

            border: 1px solid #ccc;

            padding: 2px;

        }

 

        .strengthLv1 {

            background-color: red;

            height: 6px;

            width: 40px;

            border: 1px solid #ccc;

            padding: 2px;

        }

 

        .strengthLv2 {

            background-color: orange;

            height: 6px;

            width: 80px;

            border: 1px solid #ccc;

            padding: 2px;

        }

 

        .strengthLv3 {

            background-color: green;

            height: 6px;

            width: 120px;

            border: 1px solid #ccc;

            padding: 2px;

        }

       

        .passpan {

            font-size: 12px;

            color:#FF5B5B;

            display: none;

            background: url;

        }

    </style>

</head>

 

<body>

    <div class="continer">

        <label>密码</label>

        <input type="text"  id="inp1" maxlength="16"> <span id="passpan" class="passpan">长度为8-16个字符</span>

        <div class="pass-wrap">

            <em>密码强度:</em>

 

            <em id="strength"></em>

 

            <div id="strengthLevel" class="strengthLv0"></div>

        </div>

    </div>

    <script>

        var inp1 = document.getElementById("inp1");

        var strength = document.getElementById("strength");

        var strengthLevel = document.getElementById("strengthLevel");

        var array = ['', '低', '中', '高'];

        inp1.onkeyup = function () {

            var level = 0;

            if (/[a-z]/.test(this.value)) {

                level++;

            }

            if (/[0-9]/.test(this.value)) {

                level++;

            }

            if (/^[a-z0-9]/.test(this.value)) {

                level++;

            }

            if (this.value.length < 6) {

                level = 0;

                document.getElementById("passpan").style.display="block";

            }else{

                document.getElementById("passpan").style.display="none";

            }

            if (level > 3) {

                level = 3;

            }

            strength.innerHTML = array[level];

            strengthLevel.className = 'strengthLv' + level;

        };

    </script>

</body>

 

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值