求一个类似于强度较强的密码验证,js或者正则都行,最好有完整的案例

密码规则:
1.至少包含一个大写、一个小写、一个数字
2.不得小于8位字符,不得大于16位
3.不能输入超过2位相同的字符(如:aaa、1111)
4.不能输入连续字符超过2位(如:123、456)
5.用户名字段不能包含在密码内

注:是java开发,jsp页面使用的

测试过,这个可以用了

 function password(psd,user){
    if(psd.length>16 || psd.length<8){
        alert("长度应为8-16");
        return false;
    }
    if(psd.match(user)){
        alert("不能含有用户名");
        return false;
    }

    if(!psd.match(/[a-z]/g)){//是否存在小写
        alert("至少有一个小写");
        return false;
    }

    if(!psd.match(/[A-Z]/g)){//是否存在大写
        alert("至少有一个大写");
        return false;
    }

    if(!psd.match(/[0-9]/g)){//是否存在数字
        alert("至少有一个数字");
        return false;
    }

    if(psd.match(/(012|123|234|345|456|567|678|789)/g)){//不能出现连续数字
        alert("不能出现连续数字超过2个");
        return false;
    }
    for(var i=0;i<psd.length;i++){
        var regex = psd.substring(i, i+1) + "{" + 3 + "}";  
        if(psd.match(regex)){//不能出现重复字符
            alert("不能出现重复字符超过2个");
            return false;
        }
    }

}

*

//判断输入密码的类型

function CharMode(iN){

if (iN>=48 && iN <=57) //数字

return 1;

if (iN>=65 && iN <=90) //大写

return 2;

if (iN>=97 && iN <=122) //小写

return 4;

else

return 8;

}

//bitTotal函数

//计算密码模式

function bitTotal(num){

modes=0;

for (i=0;i if (num & 1) modes++;
num>>>=1;

}

return modes;

}

//返回强度级别

function checkStrong(sPW){

if (sPW.length<=4)

return 0; //密码太短

Modes=0;

for (i=0;i<sPW.length;i++){

//密码模式

Modes|=CharMode(sPW.charCodeAt(i));

}

return bitTotal(Modes);

}

//显示颜色

function pwStrength(pwd){

O_color="#eeeeee";

L_color="#FF0000";

M_color="#FF9900";

H_color="#33CC00";

if (pwd==null||pwd==''){

Lcolor=Mcolor=Hcolor=O_color;

}

else{

S_level=checkStrong(pwd);

switch(S_level) {

case 0: Lcolor=Mcolor=Hcolor=O_color;

case 1: Lcolor=L_color; Mcolor=Hcolor=O_color; break;

case 2: Lcolor=Mcolor=M_color; Hcolor=O_color; break;

default: Lcolor=Mcolor=Hcolor=H_color;

}

}

document.getElementById("strength_L").style.background=Lcolor;

document.getElementById("strength_M").style.background=Mcolor;

document.getElementById("strength_H").style.background=Hcolor;

return;

}

可以照着你的需求改动一下

不知道这个有没有用,没测试,照着写的
var jsCheck=function(){
var check=$("#password").val();
var userName=$("#userName").val();
boolean flag=true;
if(check.length16){
flag=false;
}
if(/!(^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?[#@*&.]).*$)/){
flag=false;
}
for (var i = 0; i < check.length;i++) {
if(i<check.length-1){
if(check.charAt(i)==check.charAt(i+1)){
flag=false;
}
}
if(i<check.length-2){
if(check.charAt(i)+1==check.charAt(i+1)&&check.charAt(i+1)+1=check.charAt(i+2)){
flag=false;
}
}
}
if(userName.indexOf(check)!=-1){
flag=false;
}
return flag;
}