Latitude Regex
Validates a decimal latitude value within the real-world range of -90 to 90 degrees, with an optional fractional component of any precision.
Regex Pattern
^-?(90(\.0+)?|[1-8]?[0-9](\.[0-9]+)?)$Pattern Breakdown
Hover over a token to see what it does.
| Token | Meaning |
|---|---|
| ^ | Anchors the match to the start of the string |
| -? | Optional leading minus sign for southern-hemisphere latitudes |
| 90(\.0+)? | The exact boundary value 90, optionally followed by a decimal point and one or more zeros (e.g. 90.0, 90.000) |
| [1-8]?[0-9](\.[0-9]+)? | Any integer from 0 to 89, optionally followed by a decimal point and one or more digits for fractional precision |
| $ | Anchors the match to the end of the string |
Detailed Explanation
What it does
This pattern validates that a string represents a latitude value between -90 and 90 degrees inclusive, with any number of decimal places. It specifically guards the 90 boundary so that only 90 or 90 followed by zeros is accepted at the extreme, while values from 0 to 89 accept arbitrary fractional digits.
Why it works
Latitude is bounded at exactly +/-90 degrees (the poles), unlike longitude which wraps around. The pattern splits into two alternatives: an exact-90 branch that only allows trailing zeros after the decimal point (since 90.5 is not a valid latitude), and a 0-89 branch built from [1-8]?[0-9] that accepts any two-digit number from 0 to 89 with unrestricted decimal digits. The optional leading '-' covers the Southern Hemisphere, and anchoring with ^ and $ ensures the entire string, not a substring, is validated.
Common use cases
- Validating latitude fields in map-based forms before geocoding or storing coordinates
- Filtering CSV or API payloads of geographic data for out-of-range latitude values
- Client-side validation for GPS coordinate entry in logistics or travel apps
- Data-quality checks before plotting points on a map to catch swapped latitude/longitude values
Edge cases
- The exact pole values '90' and '-90' are valid, but '90.5' and '-90.1' are correctly rejected since latitude cannot exceed 90 degrees
- '90.0' and '90.000' are accepted because trailing zeros after the decimal point still represent exactly 90 degrees
- A bare integer like '45' (no decimal point) is valid, since the fractional part is optional
- Values with many decimal places, such as '40.712776', are accepted since digit count is unrestricted
Limitations
- Does not validate the format of an accompanying longitude value; pair with a longitude or combined lat/lng pattern for full coordinate validation
- Correctly rejects multi-digit leading zeros like '045' since [1-8]?[0-9] only allows a single optional leading digit before the final digit
- Treats '90.1' as invalid even though some lenient systems might round it; strict range checking is by design here
- Does not perform any unit conversion (e.g. from DMS - degrees/minutes/seconds - notation), only validates plain decimal degrees
Interactive Tester
Edit the pattern or text below — matching runs live in your browser.
Test Cases
Editable — add your own inputs to see if they pass.
| Input | Expected | Result | |
|---|---|---|---|
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass | |||
| Pass |
Language Variants
Production-ready examples in 12 languages.
const latitudeRegex = /^-?(90(\.0+)?|[1-8]?[0-9](\.[0-9]+)?)$/;
console.log(latitudeRegex.test('40.7128')); // trueCommon Mistakes
Using a simple range-free pattern like ^-?[0-9]+(\.[0-9]+)?$ that accepts any number, including clearly invalid latitudes like '200'
Fix: Bound the integer part to 0-90 with an explicit alternation instead of accepting arbitrary digit counts
Allowing '90.5' or other non-zero decimals at the 90 boundary, which is not a valid latitude
Fix: Special-case the 90 boundary to only allow trailing zeros after the decimal point, as in 90(\.0+)?
Confusing latitude's +/-90 range with longitude's +/-180 range and reusing the same bound
Fix: Use a dedicated latitude pattern (max 90) and a separate longitude pattern (max 180) rather than sharing one
Performance Notes
- The alternation between the 90-boundary branch and the 0-89 branch is small and non-overlapping, so backtracking cost is negligible
- Anchoring with ^ and $ allows the engine to fail fast on clearly out-of-range or non-numeric input
- For bulk validation of large coordinate datasets, precompile the regex once and combine with a numeric range check for extra safety against locale-specific formatting
Browser Compatibility
| Engine | Supported | Notes |
|---|---|---|
| Chrome | Yes | — |
| Firefox | Yes | — |
| Safari | Yes | — |
| Edge | Yes | — |
| Node.js | Yes | — |