[Vuejs]-Cross Field Validation

0👍

maybe you can just use :rules="{required: true, digits:4}" instead?

import {digits} from 'vee-validate/dist/rules';
extend('digits', {
  ...digits,
  message: `only four digits ...!!!!`,
})

or

extend("equalFourDigits", {
  validate: (value) => {
    const regex = new RegExp(/^\d{4}$/)
    if (regex.test(value)) {
      return true;
    }
    return `Your code must be 4 digits. ${value}`;
  },
});

Leave a comment