PHP技术论坛

标题: jQuery 密码验证 字母加数字或符号的组合密码 [打印本页]

作者: admin    时间: 2016-3-1 14:13
标题: jQuery 密码验证 字母加数字或符号的组合密码
  1. function validPsw() {  
  2.     var password = $(".password").val();  
  3.     var num = 0;  
  4.     var number = 0 ;  
  5.     var letter = 0 ;  
  6.     var bigLetter = 0 ;  
  7.     var chars = 0 ;  
  8.       
  9.     if (password.search(/[0-9]/) != -1) {  
  10.         num += 1;  
  11.         number =1;  
  12.     }  
  13.     if (password.search(/[A-Z]/) != -1) {  
  14.         num += 1;  
  15.         bigLetter = 1 ;  
  16.     }  
  17.     if (password.search(/[a-z]/) != -1) {  
  18.         num += 1;  
  19.         letter = 1 ;  
  20.     }  
  21.     if (password.search(/[^A-Za-z0-9]/) != -1) {  
  22.         num += 1;  
  23.         chars = 1 ;  
  24.     }  
  25.     if (num >= 2 && (password.length >= 6 && password.length <= 16)) {  
  26.         $(".pswSpan").html("");  
  27.         $(".password").css("border","#B0B0B0 solid 1px");  
  28.     }else if(password.length < 6 || password.length > 16){  
  29.         $(".pswSpan").html("密码由6-16个字符组成!");  
  30.         $(".password").css("border","#B35D5D solid 1px");  
  31.     }else if(num == 1){  
  32.         if(number==1){  
  33.             $(".pswSpan").html("不能全为数字!");  
  34.         }  
  35.         if(letter==1){  
  36.             $(".pswSpan").html("不能全为字母!");  
  37.         }  
  38.         if(bigLetter==1){  
  39.             $(".pswSpan").html("不能全为字母!");  
  40.         }  
  41.         if(chars==1){  
  42.             $(".pswSpan").html("不能全为字符!");  
  43.         }  
  44.         $(".password").css("border","#B35D5D solid 1px");  
  45.     }  
  46. }  
复制代码





欢迎光临 PHP技术论坛 (http://php.hh85.com/) Powered by Discuz! X3.2