joi object id validation
npm i joi-objectid
const Joi = require('joi');
Joi.objectId = require('joi-objectid')(Joi)
// now you can use Joi.objectId to validate the post request sent by user
joi object id validation
npm i joi-objectid
const Joi = require('joi');
Joi.objectId = require('joi-objectid')(Joi)
// now you can use Joi.objectId to validate the post request sent by user
Joi validation
const joi = require("joi");
const validation = joi.object({
userName: joi.string().alphanum().min(3).max(25).trim(true).required(),
email: joi.string().email().trim(true).required(),
password: joi.string().min(8).trim(true).required(),
mobileNumber: joi.string().length(10).pattern(/[6-9]{1}[0-9]{9}/).required(),
birthYear: joi.number().integer().min(1920).max(2000),
skillSet: joi.array().items(joi.string().alphanum().trim(true)).default([]),
is_active: joi.boolean().default(true),
});
joi regex validate
Joi.string().regex(/^[a-zA-Z0-9_][a-zA-Z0-9_.]*/)
Joi validation "Joi.when()"
Joi.object().keys({
contact: Joi.object().keys({
first_name: Joi.string(),
last_name: Joi.string(),
phone: Joi.string(),
}),
address: Joi.object().keys({
place: Joi.string(),
city: Joi.string().min(2).max(30),
street: Joi.string(),
house_number: Joi.string()
}).when('contact', {
is: Joi.object().keys({
first_name: Joi.exist(),
last_name: Joi.exist(),
phone: Joi.exist(),
}),
then: Joi.object({ place: Joi.required() }).required(),
otherwise: Joi.object({ place: Joi.forbidden() })
}),
passengers_amount: Joi.number(),
notes: Joi.string()
});
Joi.validate
function responseValidate(response) {
const schema = {
id: Joi.objectId().required(),
response: Joi.string().min(3).max(512).required()
};
return schema.validate(response);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us