Is it possible to validate that a boolean is true
using Joi? I've tried using allow
, valid
and invalid
without any luck.
Joi can be used for creating schemas (just like we use mongoose for creating NoSQL schemas) and you can use it with plain Javascript objects. It's like a plug n play library and is easy to use. On the other hand, express-validator uses validator. js to validate expressjs routes, and it's mainly built for express.
Hapi Joi is an object schema description language and validator for JavaScript objects. With Hapi Joi, we create blueprints or schemas for JavaScript objects (an object that stores information) to ensure validation of key information.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With