Using Joi, Validating That a Boolean Is True

Using Joi, Validating That a Boolean Is True

Is it possible to validate that a boolean is true using Joi? I've tried using allow, valid and invalid without any luck.

1 Answer

Have you tried something like this:

var schema = Joi.boolean().invalid(false);

Using that schema, the following all populate the error property:

Joi.validate(false, schema);
Joi.validate('false', schema);
Joi.validate('no', schema);
Joi.validate('off', schema);
Joi.validate(0, schema);
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.