validating
10Quick and easy validators for node.js and the browser.
Validating
Installation
Via npm:
npm install --save validating
or bower:
bower install --save validating
Usage
Create a function which can validate objects
var validating = require('validating');
var userDescriptors = {
name: {
rules: [
['required'],
['regexp', {pattern: /^[A-Za-z][A-Za-z0-9]*$/}]
]
},
email: {
rules: [
{name: 'email'},
{name: 'required'}
]
}
};
var validateUser = validating.forDescriptors(userDescriptors);
var result = validateUser({
name: null,
email: 'not a valid email address...'
});
console.log(result.valid);
console.log(result.errors);
Running the tests
First, npm install
, then npm test
. Code coverage generated with npm run coverage
.
License
MIT, see LICENSE.md.