✔ Please choose a unique username for your account
The validation messages returned by the validator are not something you should be showing to your end-users and instead define a set of custom messages, which are more thoughtful and easy to act upon.
✔ Please choose a unique username for your account
✖ required validation failed on username
Messages are defined as an object of key/value pairs and passed to the validate
method as 3rd argument.
const messages = {
required: 'The field is required'
}
validate(data, rules, messages)
Also you can define a different message for each field.
const messages = {
'username.required': 'Please choose a unique username for your account',
'email.required': 'Enter a valid email address.'
}
And same is true for nested arrays.
const messages = {
'users.*.username.required': 'Please choose a unique username for your account'
}