Socket
Book a DemoInstallSign in
Socket

validate-json-schema-form

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-json-schema-form

Validate a form using JSON schema

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

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

License

MIT

Keywords

json

FAQs

Package last updated on 25 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts