Module: mongoose-validator

Validators for Mongoose.js utilising validator.js
Author:
  • Lee Powell lee@leepowell.co.uk
Source:

(require("mongoose-validator"))(options) → {object}

Create a validator object
Parameters:
Name Type Description
options object Options object
Properties
Name Type Attributes Default Description
validator string Validator name to use
arguments * <optional>
[] Arguments to pass to validator. If more than one argument is required an array must be used. Single arguments will internally be coerced into an array
passIfEmpty boolean <optional>
false Weather the validator should pass if the value being validated is empty
message string <optional>
Error Validator error message
Source:
Throws:
  • If validator option property is not defined
  • If validator option is not a function or string
  • If validator option is a validator method (string) and method does not exist in validate.js or as a custom validator
Returns:
Returns validator compatible with mongoosejs
Type
object
Example
require('mongoose-validator').validate({ validator: 'isLength', arguments: [4, 40], passIfEmpty: true, message: 'Value should be between 4 and 40 characters' )

Members

(static) defaultErrorMessages

Default error messages
Source:

Methods

(static) extend(name, fn, msgopt) → {undefined}

Extend the mongoose-validator with a custom validator
Parameters:
Name Type Attributes Default Description
name string Validator method name
fn function Validator method function
msg string <optional>
Error Validator error message
Source:
Throws:
  • If name is not a string
  • If validator is not a function
  • If message is not a string
  • If name is empty i.e ''
  • If a validator of the same method name already exists
Returns:
Type
undefined
Example
require('mongoose-validator').extend('isString', function (str) { return typeof str === 'string' }, 'Not a string')