1npm i joi-objectid
2
3const Joi = require('joi');
4Joi.objectId = require('joi-objectid')(Joi)
5
6// now you can use Joi.objectId to validate the post request sent by user
1const joi = require("joi");
2
3const validation = joi.object({
4 userName: joi.string().alphanum().min(3).max(25).trim(true).required(),
5 email: joi.string().email().trim(true).required(),
6 password: joi.string().min(8).trim(true).required(),
7 mobileNumber: joi.string().length(10).pattern(/[6-9]{1}[0-9]{9}/).required(),
8 birthYear: joi.number().integer().min(1920).max(2000),
9 skillSet: joi.array().items(joi.string().alphanum().trim(true)).default([]),
10 is_active: joi.boolean().default(true),
11});
12
1function responseValidate(response) {
2 const schema = {
3 id: Joi.objectId().required(),
4 response: Joi.string().min(3).max(512).required()
5 };
6
7 return schema.validate(response);
8}
9