zoukankan      html  css  js  c++  java
  • [原创 js]验证表单强度的js

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <input type="text" id="test" />
    <script type="text/javascript">
    function validate(value,lengthObj){
        var type;
        if(/^\s*$/.test(value))
        {
            type = 0;
        }
        else if(/^[a-z]+$/.test(value))
        {
            type = 1;
        }
        else if(/^[A-Z]+$/.test(value))
        {
            type = 1;
        }
        else if(/^[0-9]+$/.test(value))
        {
            type = 1;
        }
        else if(value.length <= lengthObj.leavl1)
        {
            type = 2;
        }
        else if(value.length > lengthObj.leavl1 && value.length <= lengthObj.leavl2)
        {
            type = 3;
        }
        else if(value.length > lengthObj.leavl2)
        {
            type = 4;
        }
        return type;
    }

    var input = document.getElementById("test");
    input.onblur = function(){
        var type = validate(input.value,{leavl1:5,leavl2:10});
        switch (type)
        {
            case 0 :
                alert("密码不能为空!");
                break;
            case 1 :
                alert("您输入的密码过于简单,不要使用纯数字或纯大/小字母的组合!");
                break;
            case 2 :
                alert("您输入的密码长度过短,一级强度密码!");
                break;
            case 3 :
                alert("您输入的密码长度一般,二级强度密码!");
                break;
            case 4 :
                alert("您输入的密码很安全,三级强度密码!");
                break;           
        }
    }
    </script>
    </body>
    </html>
  • 相关阅读:
    【YbtOJ#20068】连通子图
    【YbtOJ#20067】糖果分配
    【GMOJ6801】模拟patrick
    【GMOJ6800】模拟spongebob
    【洛谷P4449】于神之怒加强版
    【洛谷P3601】签到题
    【洛谷P2408】不同子串个数
    【洛谷P3809】【模板】后缀排序
    【JZOJ1753】锻炼身体
    【GMOJ1164】求和
  • 原文地址:https://www.cnblogs.com/cly84920/p/4427057.html
Copyright © 2011-2022 走看看