Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vee-validate Custom validation rules not working

Versions:

  • 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 a base template.

I wants to use a custom validation for password. So I created a resources\assets\js\validators\passwordValidators.js file with 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 am addingv-validate="'password'" It produce an error[vee-validate] No such validator 'password' exists

Any help will be appreciated.

like image 999
Abu Sufian Avatar asked Jul 30 '17 06:07

Abu Sufian


1 Answers

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

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

v-validate = "password"

Or you can also use the object notation when you have more then 1 and complex rules.

v-validate = "{password: true}"

Regards Ben

like image 63
Ben Croughs Avatar answered Oct 13 '22 20:10

Ben Croughs