Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
/ verificator Public archive

Client and server-side validation JavaScript library

License

Notifications You must be signed in to change notification settings

stenin-nikita/verificator

Repository files navigation

Verificator

Build Status codecov npm version npm downloads npm

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: '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 => {})

License

The MIT License (MIT). Please see License File for more information.

Releases

No releases published

Packages

No packages published