1.密码必须包含数字,字母和特殊符号。
/^([a-zA-Z]+[0-9]+[,._!@#$%^&*]+)|([a-zA-Z]+[,._!@#$%^&*]+[0-9]+)|([0-9]+[,._!@#$%^&*]+[a-zA-Z]+)|([0-9]+[a-zA-Z]+[,._!@#$%^&*]+)|([,._!@#$%^&*]+[a-zA-Z]+[0-9]+)|([,._!@#$%^&*]+[0-9]+[a-zA-Z]+)$/
2.密码必须包含大小写字母,特殊字符和数字,且长度不低于8位,不多于12位。
/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*,\._])[0-9a-zA-Z!@#$%^&*,\\._]{8,12}$/
3.密码中不得包含系统默认密码admin,password等及其变种。
const validatePass = (rule, value, callback) => {
if (value === "") {
callback(new Error("请设置密码"));
} else {
if (
value.includes("admin") ||
value.includes("root") ||
value.includes("password") ||
value.includes("r00t") ||
value.includes("weblogic")
) {
callback(
new Error("密码中不得包含系统默认密码admin,password等及其变种")
);
} else {
callback();
}
}
};
4.密码不能连续字符(如123、abc)连续3位或3位以上。
setThr(str) {
//不能连续字符(如123、abc)连续3位或3位以上
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;
}
}
if (!flag) {
return flag;
}
return flag;
}
5.密码不能相同字符(如111、aaa)连续3位或3位以上。
const validatePass4 = (rule, value, callback) => {
var re = /(\w)*(\w)\2{2}(\w)*/g;
if (value === "") {
callback(new Error("请设置密码"));
} else {
if (re.test(value)) {
callback(new Error("密码不能相同字符(如111、aaa)连续3位或3位以上"));
} else {
callback();
}
}
};
elementui的弹窗写法
const ipReg = new RegExp(/^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*,\._])[0-9a-zA-Z!@#$%^&*,\\._]{8,50}$/);
this.$prompt('请输入"' + row.username + '"的密码', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type:"warning",
inputPattern: ipReg,
inputErrorMessage: "密码必须包含大小写字母以及数字和特殊符号,且长度不小于8位"
})