vue 表单校验密码

html 代码


 
      
    
    
      
    



 js 代码

data() {
const equalToPassword = (rule, value, callback) => {
      if (this.user.newPassword !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
return {

// 表单校验
      rules: {
        newPassword: [
          {required: true, message: "密码不能为空", trigger: "blur"},
          {
            pattern: /^.*(?=.{8,20})(?=.*\d)(?=.*[A-Z]{1,})(?=.*[a-z]{1,})(?=.*[!@$%^&*?\(\)]).*$/,
            message: '用户密码长度必须介于 8 和 20 之间,必须包含大写字母,小写字母,数字及特殊符号', trigger: 'blur',
          }
        ],
        confirmPassword: [
          {required: true, message: "确认密码不能为空", trigger: "blur"},
          {required: true, validator: equalToPassword, trigger: "blur"},
        ]
      }
}


}

你可能感兴趣的:(vue.js)