Home

Awesome

mongoose-validators

Build Status NPM Downloads NPM Version

validator.js for Mongoose schemas.

Installation

npm install mongoose-validators

Usage

var mongoose = require('mongoose'),
    validators = require('mongoose-validators');

// single validator
var Schema = new mongoose.Schema({
    email: {type: String, validate: validators.isEmail()}
});

// multiple validators
var Schema = new mongoose.Schema({
    username: {type: String, validate: [validators.isAlphanumeric(), validators.isLength(2, 60)]}
});

Options

Each validator type can be passed an optional options object as the first argument. The following common options can be defined:

Validators

Same as with validator.js:

Testing

Run mocha tests using:

``` npm test````