valide

1.0.0 • Public • Published

Valide

Valide is simple, chainable, multi lingual data validator.

Installation

To install the stable version:

npm install --save valide

This assumes you are using npm as your package manager.

If you're not, you can access these files on unpkg, download them, or point your package manager to them.

Browser Compatibility

Valide.js currently is compatible with browsers that support at least ES3.

Example usage

import { Valide } from 'valide';
 
function validateEmail(value) {
  return new Valide(value)
    .required()
    .email()
    .error('E-mail :email is invalid!', { email: value })
    .check();
}
 
validateEmail(''); // -> "Field is required"
validateEmail('foo'); // -> "E-mail foo is invalid!"
validateEmail('foo@example.com'); // -> true

Valide chain must always end with .check() to evaluate value. Check method also can take in new value to check against rule set.

Every rule can have custom error message. To add it, simply chain .error(string [, params]) after rule. By default every rule has english error message.

Currently available rules:

  • required, .required()
  • test, .test(regex)
  • includes, .includes(string)
  • excludes, .excludes(string)
  • equal, .equal(string)
  • notEqual, .notEqual(string)
  • min, .min(number)
  • max, .max(number)
  • email, .email(string)

  • error, .error(string [, params])

Stay In Touch

License

MIT

Copyright (c) 2017-present, Marcis (Marcisbee) Bergmanis

Package Sidebar

Install

npm i valide

Weekly Downloads

23

Version

1.0.0

License

MIT

Unpacked Size

63.6 kB

Total Files

17

Last publish

Collaborators

  • marcisbee