Vee-validate Custom validation rules do not work

Version:

  • VueJs: 2.2.6
  • Vee-Validate: ^ 2.0.0-beta.25

Description:

I am working on a project where I use laravel-vue-starter as the base template.

I want to use custom password verification. So I created a resource file \ assets \ js \ validators \ passwordValidators.js with the code:

import { Validator } from 'vee-validate';

Validator.extend('password', {
    getMessage: field => 'Insert a strong password, it should contain Uppercase letter, lowercase letter, number and special character',
    validate: value => /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.[\W]).{8,}$/.test(value)
});

But when I add v-validate="'password'" it leads to an error[vee-validate] No such validator 'password' exists

Any help would be appreciated.

+4
source share
1 answer

I think the answer is simple, now you use the rule name 'password', but your rule is the password.

So, try this in your markup (string designation), remove single quotes.

v-validate = "password"

, 1 .

v-validate = "{password: true}"

+1

Source: https://habr.com/ru/post/1682594/


All Articles