validity-number-in-range
Validity style validator to ensure a property is numeric and within an upper and lower bound. null
is allowed – use in conjunction with validity.required
if this property must exist.
Installation
npm install validity-number-in-range
Usage
Below is a simple example for usage with schemata:
var validity = schemata = createRangeValidator = var schema = schema schema
API
var validate = createRangeValidator(Number:min, Number:max)
Pass in the minimum and maximum numeric values allowed. These are inclusive – i.e. with
min=10
and max=20
, 10
and 20
are both valid. Both max
and min
are optional.
Defaults: min=Number.NEGATIVE_INFINITY
, max=Number.POSITIVE_INFINITY
validate(String:key, String:keyDisplayName, Object:object, Function:cb)
This is a validity compatible function, which in turn is used by schemata for schema validation.
The callback signature cb(err, errorMessage)
.
err
is anError
object if something bad happened andnull
otherwise.errorMessage
is aString
if a validation error happened andundefined
otherwise.
Licence
Licensed under the New BSD License