Street Address (US Format) Regex for PHP
/^[0-9]{1,6}(?:\s+(?:apt|unit|ste|suite|#)\s*[A-Za-z0-9]+)?\s+[A-Za-z0-9\s.'-]{3,50}(?:\s+(?:ave|avenue|blvd|boulevard|ct|cir|dr|drive|hwy|highway|ln|lane|pkwy|parkway|pl|place|rd|road|st|street|ter|terrace|trl|trail|way))?\.?$/iWhat this pattern does
This page provides a comprehensive, battle-tested regular expression for matching street address (us format), 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
// Street Address (US Format)
// ReDoS-safe | RegexVault — Identity & PII > Location PII
define('STREET_ADDRESS_US_FORMAT_PATTERN', '/^[0-9]{1,6}(?:\s+(?:apt|unit|ste|suite|#)\s*[A-Za-z0-9]+)?\s+[A-Za-z0-9\s.\'-]{3,50}(?:\s+(?:ave|avenue|blvd|boulevard|ct|cir|dr|drive|hwy|highway|ln|lane|pkwy|parkway|pl|place|rd|road|st|street|ter|terrace|trl|trail|way))?\.?$/');
function validate_street_address_us_format(string $input): bool {
return (bool) preg_match(STREET_ADDRESS_US_FORMAT_PATTERN, $input);
}
// Example
var_dump(validate_street_address_us_format("123 Main St")); // bool(true)Test Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
123 Main St | Main St |
456 Elm Avenue | 123 |
789 Oak Blvd | Just A Name |
1000 Willow Lane Apt 5B | — |
1 Infinite Loop | — |
123 Main | — |
When to use this pattern
This pattern is drawn from the Identity & PII > Location PII category and carries a ReDoS-safe certification. 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
Address validation regex cannot verify that an address is deliverable. Use USPS CASS-certified address validation for mail delivery. For geocoding, use a geocoding API (Google Maps, Here).
Technical Notes
US addresses are extremely varied — this pattern covers the most common format but not all. PO Boxes, rural routes, and military addresses require different patterns. Use a dedicated address validation API (USPS, SmartyStreets) for reliable validation.
Have a pattern that belongs in the vault?
Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.
Submit a Pattern