joi js

Solutions on MaxInterview for joi js by the best coders in the world

showing results for - "joi js"
Ivanna
19 Sep 2017
1const Joi = require('@hapi/joi');
2
3const joiSchema = Joi.object({
4  a: Joi.string()
5    .min(2)
6    .max(10)
7    .required()
8    .messages({
9      'string.base': `"a" should be a type of 'text'`,
10      'string.empty': `"a" cannot be an empty field`,
11      'string.min': `"a" should have a minimum length of {#limit}`,
12      'any.required': `"a" is a required field`
13    })
14});
15
16const validationResult = joiSchema.validate({ a: 2 }, { abortEarly: false });
17console.log(validationResult.error); // expecting ValidationError: "a" should be a type of 'text'