10
votes

I am using Node Joi for validation. I am new in node I want to validate env to accept only 2 words "Yes" or "No" What changes I have to make in the following code

schema = Joi.object().keys({
    app_id: Joi.string().required(),
    env: Joi.string().required()
});
1

1 Answers

20
votes

You can use valid function to define valid values for the field:

schema = Joi.object().keys({
    app_id: Joi.string().required(),
    env: Joi.string().valid("Yes", "No").required()
});