joi.js
const Joi = require('@hapi/joi');
const joiSchema = Joi.object({
a: Joi.string()
.min(2)
.max(10)
.required()
.messages({
'string.base': `"a" should be a type of 'text'`,
'string.empty': `"a" cannot be an empty field`,
'string.min': `"a" should have a minimum length of {#limit}`,
'any.required': `"a" is a required field`
})
});
const validationResult = joiSchema.validate({ a: 2 }, { abortEarly: false });
console.log(validationResult.error); // expecting ValidationError: "a" should be a type of 'text'
Also in JavaScript:
- set in Dynamo DB not properly incrementing nodejs lamnda function
- jquery element width
- difference between setTimeout() and setInterval()
- add variable inside regex in javascript
- object destructuring into this
- get hash js
- javascript online test
- typeof array javascript
- get width of a dom element js
- anagram js
- jquery count selected options
- potencia em javascript
- if parameter is not number in js
- queryselector name attribute
- angular generate component without spec
- html bind js file
- smooth scroll react
- filter in js
- how to print an element in javascript
- react toastify does not have design
- Material-ui wheelchair icon
- how to create a point in js
- lodash pascal case
- await in angular 8