'Validate negative to positive ranged number Joi

I am trying to validate latitude and longitude though Joi.

Allowed latitude number range is -90 to +90
Allowed longitude number range is -180 to +180

const schema = Joi.object({
    map_lat: Joi.number()
      .min(-90)
      .max(90)
      .messages({ 'number.base': "Invalid latitude!" }),
    map_lng: Joi.number()
      .min(-180)
      .max(180)
      .messages({ 'number.base': "Invalid longitude!" }),
  })

I am getting below error.

Error: limit must be a positive integer or reference

I also tried :

map_lng: Joi.number()
    .positive()
    .negative()
    .min(-90)
    .max(90)

But still getting same error.
Anyone can help How can I validate -ve to +ve ranged values?



Solution 1:[1]

I found a way there is greater() and less() for numbers in the doc here

const schema = Joi.object({
    map_lat: Joi.number()
      .greater(-90)
      .less(90)
      .messages({ 'number.base': "Invalid latitude!" }),
    map_lng: Joi.number()
      .greater(-180)
      .less(180)
      .messages({ 'number.base': "Invalid longitude!" }),
  })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1