npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

validate-json-schema-form

1.0.2

@yoshuawuyts

npmHomeRepoSnykSocket
Downloads:10
$ npm install validate-json-schema-form
DailyWeeklyMonthlyYearly

validate-json-schema-form

NPM version build status Test coverage Downloads js-standard-style

Validate a form using JSON Schema.

Installation

$ npm install validate-json-schema-form

Usage

<form id="signup-form">
  <input name="username" type="text" placeholder="username"></input>
  <input name="password" type="password" placeholder="password"></input>
</form>
const validator = require('validate-json-schema-form')

const validate = validator({
  required: [ 'username' ],
  type: 'object',
  properties: {
    username: { type: 'string' },
    password: { type: 'string' }
  }
})

const form = document.querySelector('#signup-form')
validate(form, (err, data) => {
  if (err) console.error(err)
  console.log(data)
})

API

validate = validator(schema)

Create a form validator out of a JSON Schema.

validate(el, [opts], cb(err, data))

Validate a form element and call a callback with the results. Opts can contain the following values:

  • [tbi] partial=false - set to true to only validate non-empty values.
  • [tbi] formats - define custom formats.
  • [tbi] schemas - reference external schemas.

See Also

  • json-schema.org
  • is-my-json-valid

License

MIT