欢迎来到【一个大西瓜】的博客

不曾为梦想奋斗,拿什么去燃烧青春。有梦之人亦终将老去,但少年心气如昨。
太阳每一个时刻都同时是夕阳和朝阳,每天她沉入西边,意味着她同时从另一面土地升起。
扩大
缩小

正则--密码强度验证

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script>
        onload = function () {
            //为文本框注册失去焦点事件,失去焦点时,进行密码验证
            document.getElementById('txtPwd').onblur = function () {
                var msg = this.value;
                //获取提示框
                var msgPwd = document.getElementById('msgPwd');
                if (msg.length < 6)
                {
                    msgPwd.innerText = "密码太短,弱爆了";
                }
                else {
                    //纯字符:弱,两种混合:中,三种混合:强
                    var pwd = 0;
                    if (/[a-zA-Z]/.test(msg)) {
                        pwd++;//有一个字母
                    }
                    if (/[0-9]/.test(msg))
                    {
                        pwd++;//有一个数字
                    }
                    if (/[!@#$%^&*()]/.test(msg)) {
                        pwd++;//有一个特殊字符
                    }
                    //提示结果
                    switch (pwd) {
                        case 1:
                            msgPwd.innerText = '弱';
                            break;
                        case 2:
                            msgPwd.innerText = '中';
                            break;
                        case 3:
                            msgPwd.innerText = '强';
                            break;

                    }
                }
            }
        }
    </script>
</head>
<body>
    <input type="text" id="txtPwd"/><span id="msgPwd"></span>
</body>
</html>

posted on 2016-11-09 14:24  一个大西瓜咚咚咚  阅读(367)  评论(0编辑  收藏  举报

导航