many
makeValidator.many(constraints)
Returns a validator function that can be used to validate many values at once.
const 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
import makeValidator from "can-validate-validatejs";
const validatePerson = makeValidator.many( {
age: {
numericality: true
},
name: {
presence: true
}
} );
const invalidPerson = {
name: "",
age: "hello"
};
validatePerson( invalidPerson ); //> {name: ['is required'], age: ['is not a number']}
const validPerson = {
name: "Juan",
age: 35
};
validatePerson( validPerson ); //> undefined