verificator
v1.0.0-beta.7
Published
Client and server-side validation JavaScript library
Downloads
13
Maintainers
Readme
Verificator
Client and server-side validation JavaScript library
Installation
To install Verificator with Yarn, run:
yarn add verificator
To install Verificator with npm, run:
npm install --save verificator
Getting Started
Using a CDN
<script crossorigin src="https://unpkg.com/verificator@latest/dist/verificator.min.js"></script>
<script crossorigin src="https://unpkg.com/verificator@latest/dist/locale/en.js"></script>
<script>
var locale = VerificatorLocale.en
Verificator.Validator.useLocale(locale)
var validator = new Verificator.Validator(data, rules)
</script>
Using a CommonJS
const Verificator = require('verificator')
const locale = require('verificator/lib/locale/en')
Verificator.Validator.useLocale(locale)
const validator = new Verificator.Validator(data, rules)
Using a ES or TypeScript
import { Validator } from 'verificator/es'
import * as locale from 'verificator/es/locale/en'
Validator.useLocale(locale)
const validator = new Validator(data, rules)
Example
import { Validator } from 'verificator/es'
import * as locale from 'verificator/es/locale/en'
Validator.useLocale(locale)
const data = {
firstName: 'Nikita',
lastName: 'Stenin',
email: '[email protected]',
}
const rules = {
firstName: 'required|string',
lastName: 'required|string',
email: 'required|string|email'
}
const validator = new Validator(data, rules)
validator.validateAll().then(isValid => {
if (isValid) {
console.log('succes')
} else {
console.log(validator.errors.all())
}
})
// or
validator.validate('firstName').then(isValid => {})
validator.validate('lastName').then(isValid => {})
validator.validate('email').then(isValid => {})
License
The MIT License (MIT). Please see License File for more information.