<el-form-item label="新密码" prop="newpasswd">
<el-input
type="password"
v-model="passwdForm.newpasswd"
placeholder="请输入新密码"
minlength="8"
>
<svgIcon
slot="prefix"
className="iconMenu"
iconName="HS-line-lock"
></svgIcon>
</el-input>
<div class="intensity">
<span class="psdText">密码强度</span>
<span
class="line"
:class="[level.includes('low') ? 'low' : '']"
></span>
<span
class="line"
:class="[level.includes('middle') ? 'middle' : '']"
></span>
<span
class="line"
:class="[level.includes('high') ? 'high' : '']"
></span>
</div>
</el-form-item>
<el-form-item label="确认密码" prop="confirmPasswd">
<el-input
type="password"
v-model="passwdForm.confirmPasswd"
placeholder="请输入确认密码"
>
<svgIcon
slot="prefix"
className="iconMenu"
iconName="HS-line-lock"
></svgIcon>
</el-input>
</el-form-item>
var validatePass = (rule, value, callback) => {
this.level = [];
if (value === "") {
return callback(new Error("请输入新密码"));
}
if (value.length < 8) {
callback(new Error("密码长度不能小于8位"));
}
if (value.length > 16) {
callback("密码不大于16位");
}
var ls = 0;
if (value.match(/([a-z])+/)) {
ls++;
}
if (value.match(/([0-9])+/)) {
ls++;
}
if (value.match(/([A-Z])+/)) {
ls++;
}
if (ls < 3) {
callback("密码数字、小写字母、大写字母各自最少含有一位,请重新输入!");
}
// 校验是数字
const regex1 = /^\d+$/;
// 校验字母
const regex2 = /^[A-Z]+$/;
// 校验字母
const regex21 = /^[a-z]+$/;
let num = 0;
// 校验符号
const regex3 =
/^[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]+$/;
if (regex1.test(value)) {
this.level.push("low");
num = num + 1;
} else if (regex2.test(value)) {
this.level.push("low");
num = num + 1;
} else if (regex21.test(value)) {
this.level.push("low");
num = num + 1;
} else if (regex3.test(value)) {
this.level.push("low");
num = num + 1;
} else if (/^[A-Za-z\d]+$/.test(value)) {
num = num + 1;
this.level.push("low");
this.level.push("middle");
} else if (
/^[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、\d]+$/.test(
value
)
) {
this.level.push("low");
this.level.push("middle");
} else if (
/^[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z]+$/.test(
value
)
) {
this.level.push("low");
this.level.push("middle");
} else if (
/^[`~!@#$%^&*()_\-+=<>?:"{}|,./;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、A-Za-z\d]+$/.test(
value
)
) {
this.level.push("low");
this.level.push("middle");
this.level.push("high");
}
return callback();
};
var validatePass2 = (rule, value, callback) => {
if (value === "") {
callback(new Error("请再次输入密码"));
} else if (value !== this.passwdForm.newpasswd) {
callback(new Error("两次输入密码不一致!"));
} else {
callback();
}
};
rules: {
newpasswd: [{ validator: validatePass, trigger: "change" }],
confirmPasswd: [{ validator: validatePass2, trigger: "change" }],
},