代码改变世界

漂亮 表单验证 密码强度

2010-02-04 14:36  曾祥展  阅读(4887)  评论(188编辑  收藏

曾祥展

 

 曾祥展

 

 

  function ClientSideStrongPassword(value) {
        var num = 1;
        if (value.trim().length == 0) {
          return num;
        }
        if (value.length > 0 && value.length < 7) {
          num = 2;
          return num;
        }

        var pat1 = /[a-zA-Z]+/;
        if (pat1.test(value)) {
          ++num;
        }
        var pat2 = /[0-9]+/;
        if (pat2.test(value)) {
          ++num;
        }
        var chr = "";
        for (var i = 0; i < value.length; i++) {
          chr = value.substr(i, 1);
          if ("!@#$%^&*()_+-='\";:[{]}\|.>,</?`~".indexOf(chr) >= 0) {
            ++num;
            break;
          }
        }
        return num;
      }
   

      function SetPwdStrengthEx(obj, value) {
        var ret = ClientSideStrongPassword(value);
        if (ret == 1) {
          $("passwd_power").className = "pwlv pwlv1";
        } else if (ret == 2) {
          $("passwd_power").className = "pwlv pwlv2";
        } else if (ret == 3) {
          $("passwd_power").className = "pwlv pwlv3";
        } else if (ret == 4) {
          $("passwd_power").className = "pwlv pwlv4";
        }
      }




调用:onkeyup="SetPwdStrengthEx(this,this.value)"