Skip to content
No description, website, or topics provided.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build
src
.babelrc
.gitignore
README.md
package-lock.json
package.json

README.md

koa-validator-middleware

A collection of validation middlewares for koa.

Usage

import {NotEmpty, Size} from 'koa-validator-middleware';
import KoaRouter from 'koa-router';

const router = new KoaRouter();

router.post('/users', 
    NotEmpty('request.body.username'), 
    Size('request.body.password', 6, 20), 
    function (ctx) {
        if(!ctx.validation.pass) {
            console.log(ctx.validation.errors);
            console.log(ctx.validation.error.username);
            console.log(ctx.validation.error.password);
        }
    }
);

API

NotEmpty(path)

NotInteger(path)

NotNumber(path)

NotNull(path)

Min(path, min)

Max(path, max)

Size(path, min, max)

Pattern(path, regExp)

Default(path, defaultValue)

You can’t perform that action at this time.