0
votes

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)
}); 
1

1 Answers

2
votes

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'
}