正则表达式判断密码是否包含⼤⼩写字母、数字、特殊字符的四种缺⼀不可,长
度8到16——CSDN博客
@[TOC]使⽤排除法⼀⼀排除
1、排除⼤⼩写字母
(?![a-zA-Z]+$)
2、排除⼤写字母和数字
(?![A-Z0-9]+$)
3、排除⼤写字母和特殊字符
(?![A-Z\\W_!@#$%^&*`~()-+=]+$)
4、排除⼩写字母和数字
(?![a-z0-9]+$)
5、排除⼩写字母和特殊字符
(?![a-z\\W_!@#$%^&*`~()-+=]+$)
6、排除数字和特殊字符
(?![0-9\\W_!@#$%^&*`~()-+=]+$)
7、排除⼤、⼩写字母和数字
(?![a-zA-Z0-9]+$)
8、排除⼤、⼩写字母和特殊字符
(?![a-zA-Z\\W_!@#$%^&*`~()-+=]+$)
9、排除⼩写字母、数字和特殊字符
(?![a-z0-9\\W_!@#$%^&*`~()-+=]+$)
10、排除⼤写字母、数字和特殊字符
(?![0-9A-Z\\W_!@#$%^&*`~()-+=]+$)
11、最后匹配这个⼤⼩写字母、数字和特殊字符的正则
[a-zA-Z0-9\\W_!@#$%^&*`~()-+=]
12、完整的正则表达式如下:
var reg =/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^&*`~()-+=]+$)(?![0-9\\W_!@#$%^&*`~()-+=]+$)(?! [a-zA-Z0-9]+$)(?![a-zA-Z\\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9\\W_!@#$%^&*`~()-+=]+$)(?![0-9A-Z\\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\\W_!@#$%^&*`~()-+ =]{8,16}$/炒南瓜
这是html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="text"id="passwords"oninput="pwd()"/><br />
<span id="icon1">*</span><span>不能相同字符(如111、aaa)连续3位或3位以上</span><br />
<span id="icon2">*</span><span>不能连续字符(如123、abc)连续3位或3位以上</span><br />
<span id="icon3">*</span><span>密码不得包含键盘上任意连续的三个字符或shift转换字符</span><br />
<span id="icon4">*</span><span>必须包含⼤⼩写字母、数字以及特殊字符,且长度在8到16位之间</span><br />
<script type="text/javascript"src="js/jquery-1.12.4.js"></script>
<script src="js/password_check.js"></script>
<script type="text/javascript">
function pwd(){
var pwds =$("#passwords").val();
//不能相同字符(如111、aaa)连续3位或3位以上
var flag1 =checkSame(pwds);
//不能连续字符(如123、abc)连续3位或3位以上
var flag2 =checkRepeat(pwds);
//密码不得包含键盘上任意连续的三个字符或shift转换字符
var flag3 =validateKey(pwds);
//必须包含⼤⼩写字母、数字以及特殊字符,且长度在8到16位之间
var flag4 =check_length(pwds);
if(flag1){
$("#icon1").css("color","green");
}else{
$("#icon1").css("color","red");
}
if(flag2){
$("#icon2").css("color","green");
}else{
$("#icon2").css("color","red");
}
if(flag3){
$("#icon3").css("color","green");
}else{
$("#icon3").css("color","red");
}
if(flag4){
$("#icon4").css("color","green");
}else{
$("#icon4").css("color","red");
}
}
</script>
</body>
</html>地狱十大恶魔
完整的JS(JS⽂件的名字叫password.js/⾃⼰创建,需要⾃⼰下⼀个jQuery⽂件)
//密码不得包含键盘上任意连续的三个字符或shift转换字符
function validateKey(str){
//定义横向穷举
var keyCode =[
["`~·","1=","2@@","3#","4$¥","5%","6^……","7&","8*","9((","0))","-_","=+"], [" ","qQ","wW","eE","rR","tT","yY","uU","iI","oO","pP","[{【","]}】","\\|、"], [" ","aA","sS","dD","fF","gG","hH","jJ","kK","lL",";:","\'\"’“"], [" ","zZ","xX","cC","vV","bB","nN","mM",",《<",".>》","/??"]
]
;
//出给出的字符串,每个字符,在坐标系中的位置。
var c = str.split("");
console.log(c)
var x =new Array();
var y =new Array();
for(var i =0; i < c.length; i++){
for(var i =0; i < c.length; i++){
var temp = c[i];
toHere:
for(var j =0; j < keyCode.length; j++){
for(var k =0; k < keyCode[j].length; k++){举重49公斤级是什么意思
var jk = keyCode[j][k];
if(jk.indexOf(temp)!=-1){
x.push(j);
y.push(k);
break toHere;
}
}
}
}
var flag =true;
for(var i =0; i < x.length -2; i++){
//如果X⼀致,那么就是在⼀排
if(x[i]== x[i +1]&& x[i +1]== x[i +2]){//四者在同⼀⾏上
if(y[i]> y[i +2]){
if(y[i]-1== y[i +1]&& y[i]-2== y[i +2]){
flag =false;
break;
}
}else{
if(y[i]+1== y[i +1]&& y[i]+2== y[i +2]){
flag =false;
break;
}
}
}else if(x[i]!= x[i +1]
qq黄钻续费&& x[i +1]!= x[i +2]
&& x[i]!= x[i +2]
){//四者均不在同⼀⾏上,但是如果y相同,说明是⼀列
if(y[i]== y[i +1]&& y[i +1]== y[i +2]){
flag =false;
break;
}
}
}
return flag;
}
//不能相同字符(如111、aaa)连续3位或3位以上
function checkSame(str){
var re =/(\w)*(\w)\2{2}(\w)*/g;
st(str)){
return false;
}else{
return true;
}
}
//不能连续字符(如123、abc)连续3位或3位以上
function checkRepeat(str){
var arr = str.split('');
var flag =true;
三种人不宜喝金银花水for(var i =1; i < arr.length-1; i++){
var firstIndex = arr[i-1].charCodeAt();
var secondIndex = arr[i].charCodeAt();
var thirdIndex = arr[i+1].charCodeAt();
thirdIndex - secondIndex ==1;
secondIndex - firstIndex==1;
if((thirdIndex - secondIndex ==1)&&(secondIndex - firstIndex==1)){ flag =false;
}
}
国庆节黑板报的图片}
return flag;
}
//必须包含⼤⼩写字母、数字以及特殊字符,且长度在8到16位之间
function check_length(str){
var reg =/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_.,/;:!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\\W_!@#$%^.,/;:&*`~()-+=]+$)(?![0-9\\W_!@#.,/;:$%^&*`~() -+=]+$)(?![a-zA-Z0-9]+$)(?![a-zA-Z\\W_!@#$%.,/;:^&*`~()-+=]+$)(?![a-z0-9\\W_!@#$%.,/;:^&*`~()-+=]+$)(?![0-9A-Z\\W_!@#.,/;:$%^&*`~
()-+=]+$)[a-zA-Z0-9\\ W_!@#$.,/;:%^&*`~()-+=]{8,16}$/;
var flag =false;
st(str)){
flag=true;
}
return flag;
}
这是只有⼩写字母、数字和特殊符号
这是四种都包含在内的
PS:特殊字符我打的⽐较少,可以⾃⼰在⾥⾯添加⼀些
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论