Skip to content

achepukov/validator-rules

Repository files navigation

Validate by user defined template

Validate by rule defined by user.

Usage

let validator = require('treeValidator');
validator.readRulesFromFile('rules.json')
// or
validator.setRules({some: {required: true;}});
validator.isValid({some: ''}); //false
//let get errors
let errors = validator.getErrors();

List of all available rules

{
  type: 'string' || 'number' || 'date' || 'email',
  required: true || false,
  format: 'dd-MM-yyyy' || 'dd-MM-yy' // for dates
  format: 'digitsBeforeComma:digitsAfterComma' // for numbers
  format: 'minLen:maxLen' // for strings
}

Version

Works fine with node version 6.9.x. May have issues with earlier releases.

FAQ

Q: May I add my own validation rules?
A: Yep, have a look here, don't forget to define: {type: 'your-awesome-custom-format', format: true}

About

Validation rules + checker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published