Coder Social home page Coder Social logo

valide's Introduction

Valide

discord

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('[email protected]'); // -> 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()
  • .test(regex)
  • .includes(string)
  • .excludes(string)
  • .equal(string)
  • .notEqual(string)
  • .min(number)
  • .max(number)
  • .email(string)

  • .error(string [, params])

Stay In Touch

License

MIT

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

valide's People

Contributors

marcisbee avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.