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

发布时间:2024年01月07日

// 自定义确认密码匹配验证规则
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>

文章来源:https://blog.csdn.net/2302_77290281/article/details/135403521
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。