Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: async-validator
node v6.17.1
endpoint
share
tweet
const Schema = require("async-validator") const obj = { value: '', test: [{ name: '', }], }; const descriptor = { test: { type: 'array', min: 2, required: true, message: '至少两项', defaultField: [{ type: 'object', required: true, message: 'test 必须有', fields: { name: { type: 'string', required: true, message: 'name 必须有' }, }, }], }, }; const validator = new Schema(descriptor); validator.validate(obj, (errors, fields) => { console.log(errors, fields); });
Created from: https://runkit.com/npm/async-validator
Loading…
no comments
sign in
to comment