演示:
代码:若以框架中resetPwd页面中:
在data()里加:
const checkPassword = (rule, value, callback) => {
if(!/[A-Z]+/.test(value) || !/[a-z]+/.test(value) || !/\d+/.test(value)
|| !/[`~!@#$%^&*()\-=_+,.?<>/;':"\[\]{}|\\]+/.test(value)) {
callback(new Error("密码必须长度必须大于10位,且包含大小写字母、数字和特殊字符"));
}
};
在rules:{}里加
//表单校验
newPassword: [
{ required: true, message: "新密码不能为空", trigger: "blur" },
{ min: 10, max: 20, message: "长度在 10 到 20 个字符", trigger: "blur" },
{ required: true, validator: checkPassword, trigger: "blur" }
],