Skip to content

ycgarrido/validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Validator

@ycgarrido/validator Validate the parameters of a request

Install

npm i @ycgarrido/validator --save

Test

npm run test

Use

const rules = {
    user: {
        store: {
            email: {
            "required": "Email is required",
            "email": "This field must be email"
            }
        }
    }
}

const validator = require("@ycgarrido/validator")(rules);

router.post('/user', (req, res) {
    validator.validate(req.body, 'user.store', ({errors}) => {
      //Save user
    });
  });

Validations


Name

Type

Summary
required Boolean, String Define if field is required
email Boolean, String Define if field must be an email
array Boolean, String Define if field must be an array
string Boolean, String Define if field must be an string
maxLength Number Define the field's max length
minLength Number Define the field's min length

About

Validate object values

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published