Monday, December 12, 2022

Javascript Joi, to validate possible values

Joi.string().valid('STUDENT', 'TEACHER').uppercase().required()

Joi support multiple date formats. 

Suppose, if we want to support multiple formats, 

Say, YYY-MM-DDTHH:mm:ss.sssZ and YYY-MM-DD, then better just check for Joi.date() 

 Also if we want to do the validation independantly for a specific string format, below can be done.

Joi.date().format("YYYY-MM-DDTHH:mm:ss.sssZ").optional(),

references:

https://www.digitalocean.com/community/tutorials/how-to-use-joi-for-node-api-schema-validation

No comments:

Post a Comment