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?

1 Answer

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!" }), }) 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.