validate a string

const yup = require("yup")
let name = "echo@mail.com";
let schema = yup.string().email() ;

schema.isValidSync(name)

run

validate a object

const yup = require("yup")
var login_schema =yup.object().shape( {
    name: yup.string().required('name is required').email(),
    pwd: yup.string().required('pass is required')
})

let name_and_pass = {
    name: '',
    pwd: ''
}

try {
    login_schema.validateSync(name_and_pass);
} catch (e ){
    console.log(e.errors);
}

run

mixed.isValid(value: any, options: ?object): Promise<boolean>
mixed.isValidSync(value: any, options: ?object): boolean

isValidSync return boolean

mixed.validate(value: any, options: ?object): Promise<any, ValidationError>
mixed.validateSync(value: any, options: ?object): any

validateSync will throw error when any of the validation fails

both of the async version return a promise of Sync version return type