async-validate
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -290,29 +290,2 @@ ## Usage | ||
## Register | ||
To extend the recognised validation types you may `register` your own validation functions by type. | ||
```javascript | ||
function register(type, validator) | ||
``` | ||
The `type` arguments should be a string indicating the `type` property of the validation rule and `validator` must be a function with the correct signature. | ||
```javascript | ||
var schema = require('async-validate'); | ||
var ValidationError = schema.ValidationError; | ||
var validator = function(rule, value, callback, source, options) { | ||
var errors = []; | ||
var re = /^[^-][a-zA-Z0-9-]+$/; | ||
if(!re.test(value)) { | ||
errors.push(new ValidationError( | ||
util.format("%s is not a valid identifier", rule.field))); | ||
} | ||
callback(errors); | ||
} | ||
schema.register('id', validator); | ||
``` | ||
You can then use validation rules such as `{type: "id"}`. | ||
## Messages | ||
@@ -319,0 +292,0 @@ |
{ | ||
"name": "async-validate", | ||
"description": "Asynchronous validation for object properties.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -24,3 +24,2 @@ Table of Contents | ||
* [Transform](#transform) | ||
* [Register](#register) | ||
* [Messages](#messages) | ||
@@ -347,29 +346,2 @@ * [Standard Rules](#standard-rules) | ||
## Register | ||
To extend the recognised validation types you may `register` your own validation functions by type. | ||
```javascript | ||
function register(type, validator) | ||
``` | ||
The `type` arguments should be a string indicating the `type` property of the validation rule and `validator` must be a function with the correct signature. | ||
```javascript | ||
var schema = require('async-validate'); | ||
var ValidationError = schema.ValidationError; | ||
var validator = function(rule, value, callback, source, options) { | ||
var errors = []; | ||
var re = /^[^-][a-zA-Z0-9-]+$/; | ||
if(!re.test(value)) { | ||
errors.push(new ValidationError( | ||
util.format("%s is not a valid identifier", rule.field))); | ||
} | ||
callback(errors); | ||
} | ||
schema.register('id', validator); | ||
``` | ||
You can then use validation rules such as `{type: "id"}`. | ||
## Messages | ||
@@ -376,0 +348,0 @@ |
96744
509