0

I'm creating a custom validation rule using VeeValidate. The offical docs uses arrow functions for the getMessage and validate methods. How do I implement these functions in the regular function syntax?

VeeValidate.Validator.extend('verify_username', {
  getMessage: field => 'Your username must be 3-24 characters long, \
    contains only a-z, 0-9, a period or an underscore, and should begin \
    with an alphabetic character.',
  validate: value => /^[a-z][a-z0-9._]{2,23}$/.test(value)
}); 
Bargain23
  • 1,863
  • 3
  • 29
  • 50

1 Answers1

2

If you don't want to use arrow function, you can just pass a normal function in its place as:

VeeValidate.Validator.extend('verify_username', {
  getMessage: function (field) {
    return "username must be..."
  },
  validate: function (value) {
    return "[...]"
  }
}); 

These functions are identical:

(foo) => 'bar'; 

is the same as:

function (foo) {
  return 'bar'
}
samayo
  • 16,163
  • 12
  • 91
  • 106
  • can you have a look at a vee-validate related question here : https://stackoverflow.com/questions/59444033/vue-js-bootstrapvue-veevalidate-cannot-validate-datepicker ? – Istiaque Ahmed Dec 22 '19 at 18:24