Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Yup

node v8.17.0
version: master
endpointsharetweet
const { object, string } = require('yup') const validationSchema = object({ firstName: string() .required("Name cannot be empty"), lastName: string() .required("Name cannot be empty"), location: object() .default(null) .nullable() .shape({ country: string().required(), state: string().required(), city: string().required() }) }) let contact = { firstName: 'jimmy', lastName: 'fred', // location: { // country: 'de', // state: 'sdf' // } } await validationSchema.validate(contact)
Or validate an object you already have:
let contact = { firstName: 'jimmy', lastName: 'fred', // location: { // country: 'de', // state: 'sdf' // } } await validationSchema.validate(contact)
Or if you want to do both at the same time:
await validationSchema.validate(contact)
If something is wrong it will let throw an error!
contact = { firstName: 'jimmy', lastName: 'fred' } await validationSchema.validate(contact, { abortEarly: false })
Loading…

no comments

    sign in to comment