1.Body代码部分
<body>
<h4>密码强度检测</h4>
<table width="100%"  border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td width="100" align="right">强度显示:</td>
    <td>
 <script language="javascript">
  var ps = new PasswordStrength();
  ps.setSize("200","20");
  ps.setMinLength(5);
 </script>
 </td>
  </tr>
  <tr>
    <td align="right">密码检测:</td>
    <td><input name="pwd" type="password" ];

 this.divName = "pwd_div_"+Math.ceil(Math.random()*100000);
 this.minLen = 5;
 
 this.width = "150px";
 this.height = "16px";
 
 this.content = "";
 
 this.selectedIndex = 0;
 
 this.init(); 
}
PasswordStrength.prototype.init = function(){
 var s = '<table cellpadding="0" ){
  return ;
 }
 n.innerHTML = this.content;
 this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.update = function(s){
 if(s.length < this.minLen){
  this.copyToStyle(0);
  return;
 }
 var ls = -1;
 if (s.match(/[a-z]/ig)){
  ls++;
 }
 if (s.match(/[0-9]/ig)){
  ls++;
 }
  if (s.match(/(.[^a-z0-9])/ig)){
  ls++;
 }
 if (s.length < 6 && ls > 0){
  ls--;
 }
  switch(ls) {
   case 0:
    this.copyToStyle(1);
    break;
   case 1:
    this.copyToStyle(2);
    break;
   case 2:
    this.copyToStyle(3);
    break;
   default:
    this.copyToStyle(0);
  }
}

相关文章: