AngularJS object validator. This is the initial implementation however, I'll be working further to improve functionality and abilities as well as observing nested objects. Better documentation will also be introduced in the near future.
install angular-object-validator
- required
- number
- array
- string
- object
- boolean
- min
- max
- greaterThan
- lessThan
- greaterThanOrEquals
- lessThanOrEquals
You can pass a single object or an array of objects to be validated.
app.controller('AppCtrl', function(ObjectValidator) {
// Set validation rules.
var rules = [
{
"quantity": [
{ 'required': 'Quantity received must be present' },
{ '{lessThanOrEquals:quantityOrdered}': 'Quantity received must be less than or equal to quantity ordered' }
]
}
];
ObjectValidator.validate([{}, {}, {}], rules).then(function() {
// Validation passed
}).catch(function(errors) {
// Errors are returned as an array
});
});