Client and server-side validation JavaScript library
To install Verificator with Yarn, run:
yarn add verificator
To install Verificator with npm, run:
npm install --save verificator
<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>
const Verificator = require('verificator')
const locale = require('verificator/lib/locale/en')
Verificator.Validator.useLocale(locale)
const validator = new Verificator.Validator(data, rules)
import { Validator } from 'verificator/es'
import * as locale from 'verificator/es/locale/en'
Validator.useLocale(locale)
const validator = new Validator(data, rules)
import { Validator } from 'verificator/es'
import * as locale from 'verificator/es/locale/en'
Validator.useLocale(locale)
const data = {
firstName: 'Nikita',
lastName: 'Stenin',
email: 'stenin.nikita@gmail.com',
}
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 => {})
The MIT License (MIT). Please see License File for more information.