Validators for Mongoose.js utilising validator.js
- Copyright:
- MIT
- Source:
(require("mongoose-validator"))(options) → {object}
Create a validator object
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | Options object
Properties
|
- 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')