PHP技术论坛

搜索
查看: 1461|回复: 0
打印 上一主题 下一主题

jQuery 密码验证 字母加数字或符号的组合密码

[复制链接]

83

主题

88

帖子

411

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
411
跳转到指定楼层
楼主
发表于 2016-3-1 14:13:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  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. }  
复制代码

相关帖子

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|PHP  

GMT+8, 2024-5-6 14:05 , Processed in 0.063099 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表