I'm attempting to implement a validation flow using the joi package, which can be found at https://www.npmjs.com/package/joi.
1) First, I want to check if the field category
exists. If it doesn't, I should display the error message category required
.
2) Next, I need to verify that the category field only allows alphabetic characters. If it contains any other characters, I should show the error message provide valid category
Below is my code snippet:
const schema = Joi.object().keys({
category: Joi.string().required().error(new Error('category is required')),
category: Joi.string().regex(/^[a-zA-Z]*$/).required().error(new Error('category is not valid')),
});
Unfortunately, the code did not work as expected.