美文网首页
正则表达式之密码强弱

正则表达式之密码强弱

作者: 小透明进击战 | 来源:发表于2019-06-16 19:33 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            #dv {
                background-color: #fafafa;
                position: absolute;
                left: 200px;
                top: 200px;
                width: 500px;
                height: 200px;
                
            }
            .strong0 {
                background-color: #ffffff;
                width: 150px;
                height: 10px;
                border: 1px dashed #cccccc;
                border-radius: 10%;
            }
            .strong1 {
                background-color: green;
                width: 50px;
                height: 10px;
                border: 1px dashed palevioletred;
                border-radius: 10%;
            }
            .strong2 {
                background-color: #DB192A;
                width: 100px;
                height: 10px;
                border: 1px dashed palevioletred;
                border-radius: 10%;
            }
            .strong3 {
                background-color: blue;
                width: 150px;
                height: 10px;
                border: 1px dashed palevioletred;
                border-radius: 10%;
            }
        </style>
    </head>
    <body>
    <div id="dv">
        <label for="pwd">请输入密码</label>
        <input type="text" name="密码框" id="pwd"/>
        <div>
            <em>密码强度</em>
            <div id="strong" class="strong0"></div>
        </div>
    </div>
    <script>
        var keyupobj=document.getElementById("pwd");
        var stobj=document.getElementById("strong");
        keyupobj.onkeyup=function(){
            //密码字符数大于6才会改变颜色
            if(this.value.length>=6){
                stobj.className="strong"+getlev(this.value);
            }else{
                stobj.className="strong0";
            }
    
        };
        //判断表单中的级别
        function getlev(pwd){
            var lev=0;
                if(/[0-9]/.test(pwd)){
                    lev++;
                }
                if(/[a-zA-Z]/.test(pwd)){
                    lev++;
                }
                if(/[^0-9a-zA-Z]/.test(pwd)){
                    lev++;
                }
            return lev;
    
        }
    </script>
    
    </body>
    </html>
    
    image.png

    相关文章

      网友评论

          本文标题:正则表达式之密码强弱

          本文链接:https://www.haomeiwen.com/subject/zwagfctx.html