JS工具类——密码强度检测类

function Password(){};
Password.check = function(pwd,tipsDivId) {
   var id = Password.getResult(pwd);
   var msg = ["密码过短","密码强度差","密码强度良好","密码强度高"];
   var sty = [-45,-30,-15,0];
   var col = ["#999999","#66CC00"];
   var sWidth = 300, sHeight = 15;
   var Bobj = $(tipsDivId);
   if(!Bobj)return;

   with(Bobj){
        style.fontSize = "12px";
        style.width = sWidth + "px";
        style.height = sHeight + "px";
        style.lineHeight = sHeight + "px";
    }
    var html = "";
    for(var i=0; i<msg.length; i++) {
    var bg_color = (i<=id)?col[1]:col[0];
        html += "<span style='width:30px;background-color="+bg_color+";'>   </span>";
    }
    Bobj.innerHTML = html;
    Bobj.title = msg[id];
};
Password.getResult = function(/*string*/pwd) {
   if(pwd.length<6) return0;
   var ls = 0;
   if(pwd.match(/[a-z]/ig)) ls++;
   if(pwd.match(/[0-9]/ig)) ls++;
   if(pwd.match(/(.[^a-z0-9])/ig)) ls++;
   if(pwd.length<6&&ls>0) ls--;
   return ls;
};


posted @ 2011-12-27 12:08  Cat.1988  阅读(158)  评论(0编辑  收藏  举报