REGEXVAULT
Identity & PII/Location PII
ReDoS Checked

GPS Coordinates (Decimal Degrees — High Precision) Regex for PHP

/^(-?(?:90(?:\.0{1,6})?|(?:[0-8][0-9]|[0-9])(?:\.[0-9]{1,8})?)),\s?(-?(?:180(?:\.0{1,6})?|(?:1[0-7][0-9]|[0-9]{1,2})(?:\.[0-9]{1,8})?))$/

All five implementations are free. Switch engines without signing in.

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching gps coordinates (decimal degrees — high precision), ported and verified for PHP. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// GPS Coordinates (Decimal Degrees — High Precision)
// ReDoS-checked | RegexVault — Identity & PII > Location PII

define('GPS_COORDINATES_DECIMAL_DEGREES_HIGH_PRECISION_PATTERN', '/^(-?(?:90(?:\.0{1,6})?|(?:[0-8][0-9]|[0-9])(?:\.[0-9]{1,8})?)),\s?(-?(?:180(?:\.0{1,6})?|(?:1[0-7][0-9]|[0-9]{1,2})(?:\.[0-9]{1,8})?))$/');

function validate_gps_coordinates_decimal_degrees_high_precision(string $input): bool {
    return (bool) preg_match(GPS_COORDINATES_DECIMAL_DEGREES_HIGH_PRECISION_PATTERN, $input);
}

// Example
var_dump(validate_gps_coordinates_decimal_degrees_high_precision("1.3521,103.8198")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
1.3521,103.819891,0
51.5074,-0.1278-91,0
-33.8688,151.20930,181
0,00,-181
90.0,-180.01.3521,103.8198,50

When to use this pattern

This pattern is drawn from the Identity & PII > Location PII category and has been checked for ReDoS risk. That matters for PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

GPS coordinate precision matters for privacy. Truncating to 2 decimal places (≈1km) is a common anonymization technique. Movement history (multiple GPS coordinates over time) constitutes location profiling — stricter treatment required.

Technical Notes

High-precision GPS (>4 decimal places) can identify a specific building or room. 4 decimal places ≈ 11m accuracy. 6 decimal places ≈ 0.1m. GPS coordinates of a home address or frequent location are personal data under GDPR.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Submissions join the review queue after automated validation.

Submit a Pattern