Giter VIP home page Giter VIP logo

node-req-validator's Introduction

Usage node-req-validator

#Install

command: sudo npm install node-req-validator

#Usage Json Validate

const Validator = require('node-req-validator');
/* instace */
let validator = new Validator({
    /*validate email*/
    eml:{data:'[email protected]',msg:'Email invalid'},
    
	/* compare password*/
	pwd:{pwd1:'pw1',pwd2:'pwd2',msg:'Pwd does not match'},
	
	/*validate  max characters*/
	max:{data:'Hello World',max:5,msg:'Max 5 characters'},	

	/*validate min cahracters*/
	min:{data:'Hello',min:6,msg:'Min 6 5 characters'},
	
	/*verify input number*/
	num:{data:'Hello', msg:'it`s not number'},
	
	/*verify input string*/
	str:{data:'1', msg:'it`s not string'},

	/*validate cpf (BR)*/
	cpf:{data:'000.000.000-000',msg:'cpf invalid'},
	
	/*validate cnpj(BR) */
	cnpj:{data:'000.000.000-000',msg:'cnpj invalid'},

	/*validate phone (BR)*/
	tel:{data:'(23)3662-323233',msg:'Phone invalid'}
});
/* validate */
if (validator.isInvalid()) 
	    return  res.status(400).send(validator.errors);

#Usage Methods Validate

const Validator = require('node-req-validator');
/* instace */
let validator = new Validator({});
validator.isEmail(email,'email invalid');
validator.notEqualsPassword(pwd1,pwd2, message);
validator.lenghtMax(str,total,message);
validator.lengthMin(str,total,message);
validator.isNumber(data,message);
validator.isString(data,message);
validator.isCpf(cpf,message);
validator.isCnpj(cnpj,message);
validator.isTelefone(tel, message);

/* validate */
if (validator.isInvalid()) 
	    return  res.status(400).send(validator.errors);

#Generate scaffold rules

const Validator = require('node-req-validator');
let validator = new Validator({});
console.log(validator.generatScaffold());

node-req-validator's People

Contributors

rafaelalveriano avatar

Stargazers

 avatar  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.