Validity style validator to ensure a property is equal to another schemata field
npm install validity-equal-field
Below is a simple example for usage with schemata:
var validity = require('validity')
, schemata = require('schemata')
, save = require('save')
, createValidator = require('validity-equal-field')
var schema = schemata(
{ password:
{ type: String
, validators: { all: [ createValidator('vpassword') ] }
}
, vpassword:
{ type: String }
})
A custom error message can also be passed createValidator('vpassword', 'Passwords do not match')
Create a validate function.
This is a validity compatible function, which in turn is used by schemata for schema validation.
The callback signature cb(err, errorMessage).
err is an Error object if something bad happened and null otherwise. errorMessage is a String if a validation error happened and undefined otherwise.
Licensed under the New BSD License