JSON Validation
Example
const validate = require('validation-unchained');
const { errors, data } = model.validate({
username: 'chris',
password: 'pass'
}, {
strict: true,
rules: {
username: { type: String },
password: { type: String, length: { min: 6, max: 255, inclusive: true } }
}
});
console.log(errors);
// => { password: [ 'Must be between 6 and 255 characters long.' ] }
Features
- Type Conversion
- Boolean
- Date
- Number
- String
- Strict enforcement
- Array Values
- All Types
- Required
- Boolean Validation
- Date Validation
- Number Validation
- Min values
- Max values
- String Validation
- Required values
- String lengths
- Regular Expression
- Custom Validation [WIP]