Skip to main content

range

$range

Validates that a numeric value falls within the specified range (inclusive). Can specify minimum, maximum, or both bounds.

Parameters

  • min (number, optional): Minimum value (inclusive). If omitted, no lower bound.
  • max (number, optional): Maximum value (inclusive). If omitted, no upper bound.

Example

// Object form with named parameters
new Schema('number').validator({$range: {min: 1, max: 100}})

// Array form [min, max]
new Schema('number').validator({$range: [1, 65535]})

// Only a lower bound (percentage, must be non-negative)
new Schema('number').validator({$range: {min: 0}})

// Only an upper bound
new Schema('number').validator({$range: {max: 255}})

See also: $positive and $negative for common named ranges.