validate-model
Validate model objects with validator.js. Read validator.js documentation to see available validators.
Installation
npm install validate-model --save
Usage
var ValidateModel = ;var validate = ValidateModelvalidate;var validateAll = ValidateModelvalidateAll; var UserValidators = name: title: 'Name' validate: validator: 'isLength' arguments: 1 255 email: title: 'Email' validate: validator: 'isLength' arguments: 20 255 message: '{TITLE} is too short' validator: 'isEmail' message: '{TITLE} must be valid' password: title: 'Password' validate: validator: 'isLength' arguments: 8 255 message: '{TITLE} is too short' ; var user = name: 'Foo' email: 'invalid@email' password: 'short'; var nameValidation = ;// { valid: true, messages: [] } var emailValidation = ;// { valid: false, messages: ['Email is too short', 'Email must be valid'] } var passwordValidation = ;// { valid: false, messages: ['Password is too short'] } var userValidation = // { valid: false, messages: {email: ['Email is too short', 'Email must be valid'], password: ['Password is too short']}}
Inspiration
This package is inspired by the way FaridSafi/react-native-gifted-form implements form validation.
Contributing
Please create issues and send pull requests!