Dynamic Validator in JS

Star Count Licence Language

npm package for easy validation in javascript.

Installation

npm install dynamic-validator.js

Syntax

Validator.Rule(validator=>{
    ... conditions here ...
});

Example

const {Validator} = require('dynamic-validator.js');

const v = Validator.Rule(
    validator=>{

        validator.input("test1","hello")
        .isArray("no array")
        .isNumber("no number")
        .isEmpty("no number")
        .customFunction(function(x){
            x.setError("hoho");
        });

        validator.input("test2","test")
        .isArray("no array")
        .isNumber("no number")
        .isEmpty("no number")
        .customFunction(function(x){
            x.setError("hoho");
        });

    }
);
if(!v.validate()){
  console.log(v.errors);
}

Function List

Function #Remark
isArray # validator.isArray(‘Error Message’);
isNumber # validator.isNumber(‘Error Message’);
isEmpty # validator.isEmpty(‘Error Message’);
isEmail # validator.isEmail(‘Error Message’);
isAllNumberinArray # validator.isAllNumberinArray(‘is not number’);

GitHub

View Github