can-validate-validatejs
Version:
Create validator functions that use ValidateJS to validate values.
51 lines (39 loc) • 1.03 kB
Markdown
can-validate-validatejs.many many
can-validate-validatejs.methods
`makeValidator.many(constraints)`
Returns a validator function that can be used to validate many values at once.
```js
const validatePerson = makeValidator.many( {
age: {
numericality: true
},
name: {
presence: true
}
} );
```
{Object} constraints A map of objects which contain definitions used by the Validate.js library.
{Validator} A [can-validate.validator] type function that takes an object of values and validates every value based on the provided constraints.
## Example
```js
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
```