JSPM

  • Created
  • Published
  • Downloads 8654
  • Score
    100M100P100Q128727F
  • License ISC

validation library

Package Exports

  • node-input-validator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-input-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Validation Library

Validation library for node.js

Note: Package is under development

Node Input Validator is a validation library for node.js. You can also extend library to add custom rules.

Installation

npm install node-input-validator

Usage

    const v = require('node-input-validator');

    let r = {};

    let validator = new v(r, {name:''}, {name:'required|minLength:5'});

    validator.check().then(function (matched) {
        console.log(matched);
        console.log(validator.errors);
    });

For Koa2 Attach koa middleware

    const validator = require('node-input-validator');
    app.use(validator.koa());

Controller Example

    let v = await ctx.validate(ctx.request.body, {
            name:'required|max:50', 
            username:'required|max:15',
            email:'required|email',
            password:'required'
        });

    
    let isValid = await v.check();

    if (!isValid) {
        // return validation errors
        ctx.body = v.errors;
    }