How can I customize the error message for a required field in Joi?

Question

Grade: Education Subject: Support
How can I customize the error message for a required field in Joi?
Asked by:
66 Viewed 66 Answers

Answer (66)

Best Answer
(178)
Use the `required()` method along with the `messages` option with the `any.required` error code: `Joi.string().required().messages({'any.required': 'This field is mandatory.'})`.