vue3自定义确认密码匹配验证规则

复制代码
// 自定义确认密码匹配验证规则
const matchPassword = (rules:any, value:any, callback:any) => {
	if (value != addData.payPwd) {
		callback(new Error('两次密码输入不一致!'))
	} else {
		callback()
	}
}


const rules = reactive({
  payPwd: [
    { required: true, message: "请输入支付密码", trigger: "blur" },
    {
      pattern: /^\d+$/,
      message: "只能输入6位数字",
      trigger: "blur",
    },
  ],
  repeatedPwd: [
    { required: true, message: "请输入支付密码", trigger: "blur" },
    {
      pattern: /^\d+$/,
      message: "只能输入6位数字",
      trigger: "blur",
    },
    {validator: matchPassword, trigger: 'blur'}
  ],
});

 <el-dialog
      v-model="AddDialog"
      title="新增会员"
      width="700px"
      @close="closeDialog"
    >
      <el-form
        ref="categoryFormRef"
        :model="addData"
        :rules="rules"
        label-width="120px"
      >
        <el-form-item label="支付密码" prop="payPwd">
          <el-input
            v-model="addData.payPwd"
            placeholder="请输入支付密码"
            show-password
            maxLength="6"
          />
        </el-form-item>
        <el-form-item label="确认支付密码" prop="repeatedPwd">
          <el-input
            v-model="addData.repeatedPwd"
            placeholder="请输入支付密码"
            show-password
            maxLength="6"
          />
        </el-form-item>
      </el-form>

      <template #footer> 
        <div class="dialog-footer">
          <el-button type="primary" @click="handleAdd">确 定</el-button>
          <el-button @click="closeDialog">取 消</el-button>
        </div>
      </template>
    </el-dialog>
相关推荐
VX:Fegn08954 小时前
计算机毕业设计|基于ssm + vue超市管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·后端·课程设计
2401_892000525 小时前
Flutter for OpenHarmony 猫咪管家App实战 - 添加提醒实现
前端·javascript·flutter
Yolanda946 小时前
【项目经验】vue h5移动端禁止缩放
前端·javascript·vue.js
VX:Fegn08957 小时前
计算机毕业设计|基于springboot + vue酒店管理系统(源码+数据库+文档)
vue.js·spring boot·课程设计
EndingCoder7 小时前
案例研究:从 JavaScript 迁移到 TypeScript
开发语言·前端·javascript·性能优化·typescript
Irene19917 小时前
Vue3 中使用的命名规则 和 实际开发命名规范总结
vue.js·命名规范
Amumu121389 小时前
Vue脚手架(二)
前端·javascript·vue.js
lichenyang4539 小时前
从零开始构建 React 文档系统 - 完整实现指南
前端·javascript·react.js
比特森林探险记9 小时前
Hooks、状态管理
前端·javascript·react.js
比特森林探险记10 小时前
组件通信 与 ⏳ 生命周期
前端·javascript·vue.js