1.密码长度不小于8
if (password.length<8){
alert("密码长度不小于8!");
return false;
}
2.密码包含大写、小写字母和数字
var reg = new RegExp("[A-Z]+|[a-z]+|[0-9]+$");
if (!reg.test(password)){
alert("密码应包含大写字母、小写字母和数字!");
return false;
}
3.密码不能包含连续数字、字母
if (_isContinuousChar(password)){
alert("密码不能包含连续数字、字母!");
return false;
}
/**
* 连续数字、字母统计3个
* @param str
* @return
*/
function _isContinuousChar(str){
str = str.toString();
flag = 0
for (var i = 0 ; i < str.length;i++){
if(i > 0){
if(Number(str.charAt(i)) == Number(str.charAt(i - 1)) + 1 ){
if(flag==1) {
return true
}
flag = 1
}
else
flag = 0
}
}
return false
}
4.密码不能包含键盘连续字符
//密码不能包含键盘连续字符
if (_isKeyBoardContinuousChar(password)){
alert("密码不能包含键盘连续字符!");
return false;
}
/**
* 键盘连续字符统计3个
* @param str
* @return
*/
function _isKeyBoardContinuousChar(str) {
var c1 = [
['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+'],
['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|'],
['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"'],
['z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?']
];
var c2 = [
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '='],
['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\''],
['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/']
];
str = str.split("");
//获取坐标位置
var y = [];
var x = [];
for (var c = 0; c < str.length; c++) {
y[c] = 0;//当做~`键处理
x[c] = -1;
for (var i = 0; i < c1.length; i++) {
for (var j = 0; j < c1[i].length; j++) {
if (str[c] == c1[i][j]) {
y[c] = i;
x[c] = j;
}
}
}
if (x[c] != -1) continue;
for (var i = 0; i < c2.length; i++) {
for (var j = 0; j < c2[i].length; j++) {
if (str[c] == c2[i][j]) {
y[c] = i;
x[c] = j;
}
}
}
}
//匹配坐标连线
for (var c = 1; c < str.length - 1; c++) {
if (y[c - 1] == y[c] && y[c] == y[c + 1]) {
if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) {
return true;
}
} else if (x[c - 1] == x[c] && x[c] == x[c + 1]) {
if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) {
return true;
}
}
}
return false;
}