0

Actually am new to this technology so my question was in my schema there is a column status. The status should active or inactive so for this i have to add joi validation.I don't know how to do it so can anyone please tell me how to do it?

Schema

const USER_SCHEMA = {
    user_full_name: Joi.string().min(3).max(20).regex(/^[ A-Za-z0-9]+$/).required(),
    user_email: Joi.string().min(5).max(50).email().required(),
    user_status: 
};
ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • here's your answer https://stackoverflow.com/questions/50156176/how-to-use-enum-values-with-joi-string-validation – Masoud Jul 01 '19 at 05:59

1 Answers1

2

You can mention a list of data you want to compare in array form like below.

const USER_SCHEMA = {
    user_full_name: Joi.string().min(3).max(20).regex(/^[ A-Za-z0-9]+$/).required(),
    user_email: Joi.string().min(5).max(50).email().required(),
    user_status: Joi.valid(['active', 'inactive']).required()
};
narayansharma91
  • 2,273
  • 1
  • 12
  • 20