validity-number-in-range

Validity style validator to ensure a property is numeric and within an upper and lower bound

validity-number-in-range

Validity style validator to ensure a property is numeric and within an upper and lower bound.

  npm install validity-number-in-range

Below is a simple example for usage with schemata:

 
var validity = require('validity')
  , schemata = require('schemata')
  , createRangeValidator = require('validity-number-in-range')
 
var schema = schemata(
    { age:
      { type: Number
      , validators: { all: [ createRangeValidator(18, 25) ] }
      }
    })
 
schema.validate({ age: 30 }, function (errorerrorMessage) {
  console.log(errorMessage) //-> 'age must be no greater than 25' 
})
 
schema.validate({ age: 20 }, function (errorerrorMessage) {
  console.log(errorMessage) //-> undefined 
})

Licensed under the New BSD License