Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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),
});
Comment

joi unique validation

const schema = Joi.array().unique((a, b) => a.property === b.property);
Comment

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()
});
Comment

joi validation

joi validation
Comment

joi validate

const schema = Joi.object({
    username: Joi.string()
        .alphanum()
        .min(3)
        .max(30)
        .required(),

});
schema.validate({ username: 'abc', birth_year: 1994 });
Comment

Joi.validate

function responseValidate(response) {
  const schema = {
    id: Joi.objectId().required(),
    response: Joi.string().min(3).max(512).required()
  };

  return schema.validate(response);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js how to sort array by string length 
Javascript :: jquery click not working on dynamic content 
Javascript :: create component with module and routing in angular 8 
Javascript :: ERESOLVE unable to resolve dependency tree 
Javascript :: how to filter nested array of objects in javascript 
Javascript :: react in laravel 
Javascript :: nextjs layout 
Javascript :: delete with body angular 
Javascript :: js check if string includes from array 
Javascript :: how to get url params value in node js 
Javascript :: isnan javascript 
Javascript :: jspdf save in server 
Javascript :: ion input ios keyboard over 
Javascript :: datatable order number 
Javascript :: converting a string into a number in javascript 
Javascript :: js convert array of arrays to array 
Javascript :: javascript break for loop 
Javascript :: react link without underline 
Javascript :: unary operator javascript 
Javascript :: wordpress jquery slide out navigation 
Javascript :: how to loop an object in javascript 
Javascript :: float to euro curency 
Javascript :: javascript date convert to unix 
Javascript :: how to convert date format using date pipe in angular 
Javascript :: how to customize js alert box 
Javascript :: not in array js 
Javascript :: uncaught typeerror is not a function javascript 
Javascript :: how to hide title bar react-navigation 
Javascript :: convert int to float in javascript 
Javascript :: javascript regex cheat sheet 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =