Skip to content

m0dch3n/js-validators

Repository files navigation

JS Validators

Credits

Credits go to https://github.com/monterail/vuelidate as the functions are taken or inspired from this project, without the vue overhead

Why this validator collection

The idea is to have a simple javascript validator collection of checks which are often used

List of current available checks

  • alpha
  • alphaNum
  • numeric
  • between
  • decimal
  • email
  • integer
  • ipv4Address
  • macAddress
  • maxLength
  • maxValue
  • minValue
  • minLength
  • required
  • requiredIf
  • requiredUnless
  • url
  • sameAs

Installation

npm install 'js-validators' --save

Usage

import email, between from 'js-validators'

console.log(email.check('test@example.com'))
console.log(email.params)

let between3And6 = between(3,6)
console.log(between3And6.check(10))
console.log(between3And6.params)

Why params ?

Simply because often, validation checks need to be translated to different languages, i.e.

between: 'This field needs to be between {min} and {max}'

Function only, without params

import {check as emailCheck} from 'js-validators/email'

console.log(emailCheck('invalidmail'))

Build & Test

# npm run build
# npm run test

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published