https://github.com/codemix/validating
Quick and easy validators for node.js and the browser.
https://github.com/codemix/validating
Last synced: 10 months ago
JSON representation
Quick and easy validators for node.js and the browser.
- Host: GitHub
- URL: https://github.com/codemix/validating
- Owner: codemix
- License: mit
- Created: 2014-06-03T18:12:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-23T23:27:29.000Z (over 11 years ago)
- Last Synced: 2025-05-06T08:51:27.907Z (11 months ago)
- Language: JavaScript
- Size: 254 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Validating
[](https://travis-ci.org/codemix/validating)
# Installation
Via [npm](https://npmjs.org/package/validating):
npm install --save validating
or [bower](http://bower.io/search/?q=validating):
bower install --save validating
# Usage
### Create a function which can validate objects
```js
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](LICENSE.md).