many
makeValidator.many(constraints)
Returns a validator function that can be used to validate many values at once.
var validatePerson = makeValidator.many({
age: {
numericality: true
},
name: {
presence: true
}
});
Parameters
- constraints
{Object}
:A map of objects which contain definitions used by the Validate.js library.
Returns
{Validator}
:
A validator type function that takes an object of values and validates every value based on the provided constraints.
Example
var makeValidator = require('can-validate-validatejs');
var validatePerson = makeValidator.many({
age: {
numericality: true
},
name: {
presence: true
}
});
var invalidPerson = {
name: '',
age: 'hello'
};
validatePerson(invalidPerson); //> {name: ['is required'], age: ['is not a number']}
var validPerson = {
name: 'Juan',
age: 35
};
validatePerson(validPerson); //> undefined