A simple JavaScript validation library that doesn't interfere.
npm install approvejsapprove.value()), you can decide how to handle validation.
master.zip into your desired folder and add a script tag to the library before the end of your closing tag
html
`
##### Bower
In your terminal run:
`
$ bower install approvejs
`
Add a script tag to the library before the end of your closing tag
`html
`
##### cdnjs
Add a script tag to the library CDN url before the end of your closing tag
`html
`
Get the cdn urls from here
Many thanks to cdnjs who kindly hosts ApproveJS through a reliable CDN
##### Node
In your terminal run:
`
$ npm install approvejs
`
or if you're using Yarn
`
$ yarn add approvejs
`
Require approvejs.
`javascript
var approve = require('approvejs');
`
---
$3
ApproveJS exposes a single method value that takes two parameters.
The first parameter is the value to validate and the second is the set of rules to test against.
`javascript
var rules = {
required: true,
email: true
};
var result = approve.value('user@domain.com', rules);
`
The returned result contains two properties:
`javascript
{
approved: boolean,
errors: []
}
`
#### Accessing Errors
You can access errors returned by the result in one of two ways:
##### Errors Property
`javascript
var i = result.errors.length;
while(i--) {
console.log(result.errors[i]);
}
`
##### .each Method
The result object exposes an each() method for easily getting to errors.
`javascript
result.each(function(error) {
console.log(error);
});
``