Custom Validator
Friendly object validation using https://github.com/chriso/validator.js. Its extended for async validation.
Requires:
Instalation
Node
npm install custom-validator
Browser
Only manual at the moment, copy files of dist foolder into your project.
Usage
TODO: Explain validator a bit more.
Here is an example that runs on node.js.On browser, you have CustomValidator global object with the same methods as the required object in node.js
For more details, you can look test/test.js file.
var validateMultiple = validateMultiple; // Populate array of validatorsvar validators = message: 'Alphanumeric' validator: 'isAlphanumeric' attr: 'username' message: 'Must be between 8 and 12 length' validator: 'isLength' args: 8 12 attr: 'username' message: 'Valid email' validator: 'isEmail' attr: 'email' message: 'Unique email' attr: 'email' { // Well... you can make a real async call here, like an AJAX request or Mongo query ifemail == 'example@example.com' ; else ; } // Create a validator objectvar validator = ; // Create a callback that will be executed after validationvar { // Check if the object is valid ifisValid == true console; else console // Check the status for each attribute console; console; // Check the status of each validation console; // Alphanumeric console; console; // Must be between 8 and 12 length console; } // Validate; // valid; // fails on email