Back to all patterns
Latitude/Longitude Coordinate Validation
Validation
Validates a latitude,longitude coordinate pair like 37.7749,-122.4194.
/^(-?(?:90(?:\.0+)?|(?:[0-8]?\d)(?:\.\d+)?)),\s*(-?(?:180(?:\.0+)?|(?:1[0-7]\d|[0-9]?\d)(?:\.\d+)?))$/How it works
Latitude ranges from -90 to 90 degrees. Longitude ranges from -180 to 180 degrees. This pattern validates both components in a comma-separated pair with optional decimal precision.
Test Cases
Should Match
- 37.7749,-122.4194
- 0,0
- -90,180
Should NOT Match
- 91,0
- 0,181
- 37.7749
- lat,lng
Quick Summary
Validates latitude,longitude coordinate pairs. Latitude: -90 to 90. Longitude: -180 to 180. Both support decimal precision. Capture group 1 is latitude, capture group 2 is longitude.
Key Takeaways
Key Takeaways
- Latitude range: -90 (South Pole) to 90 (North Pole)
- Longitude range: -180 (International Date Line West) to 180 (International Date Line East)
- Capture group 1: latitude; capture group 2: longitude
- Does not validate that the coordinate falls on land or in a specific region
Use Cases
When to use it
- Validating GPS coordinate inputs in mapping applications
- Parsing location data from CSV or JSON files
- Checking coordinate fields in geospatial API requests
Watch out
Common Mistakes
- Confusing latitude and longitude order, latitude comes first in most conventions
- Not handling the full decimal precision needed for precise location (6 decimal places = ~0.1m accuracy)
FAQ
Latitude/Longitude Coordinate Validation, Frequently Asked
How many decimal places do I need for GPS coordinates?
6 decimal places gives ~0.1m accuracy. 4 decimal places gives ~11m accuracy. Most applications need 4-6 decimal places.
What coordinate system does Google Maps use?
Google Maps uses WGS84 (World Geodetic System 1984), the same system used by GPS.