Pattern library / Dates & Time
US Date Regex (MM/DD/YYYY)
American exports write 12/31/2026; European ones write the same numbers reversed. This pattern pins the US order — month first, both parts zero-padded, ranges enforced — and the pitfalls explain why 13/01/2026 proving wrong proves nothing about which side of the Atlantic your data came from.
How the pattern works
(0[1-9]|1[0-2])— month 01–12 in the FIRST slot: that placement is the US-order claim of this pattern.(0[1-9]|[12][0-9]|3[01])— day 01–31 second; ISO2026-12-31and dotted EU31.12.2026fail by design.- Loose (unpadded) variant:
^(0?[1-9]|1[0-2])/(0?[1-9]|[12][0-9]|3[01])/[0-9]{4}$— accepts1/5/2026too. - Ambiguity is real: any date with day ≤ 12 (
04/05/2026) is legal US and legal EU. Regex cannot resolve it — only the source's locale can.
Test it: match & no-match examples
Every row is loaded straight into the tester — click Try to see the match live:
| Input | Result | Why | |
|---|---|---|---|
12/31/2026 | Match | December 31, US order | Try → |
01/05/2026 | Match | January 5, zero-padded | Try → |
06/15/2026 | Match | day over 12 proves US order | Try → |
13/01/2026 | No match | no month 13 | Try → |
1/5/2026 | No match | unpadded — strict form wants 01/05 (loose variant in notes) | Try → |
31/12/2026 | No match | European order lands day in the month slot | Try → |
Where to use it
JavaScript
const US = /^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/[0-9]{4}$/;
US.test('12/31/2026'); // true
Python (validate, then parse)
import re
US = r'^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/[0-9]{4}$'
bool(re.fullmatch(US, '12/31/2026')) # True
from datetime import datetime
datetime.strptime('12/31/2026', '%m/%d/%Y') # unambiguous parse
BigQuery (RE2)
WHERE REGEXP_CONTAINS(date_str, r'^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/[0-9]{4}$')
Common mistakes
- You cannot distinguish US from EU order for days 01–12.
04/05/2026is April 5 in the US, May 4 in Europe — resolve by locale metadata, never by the numbers. - Shape is not calendar:
02/31/2026passes (month 02, day 31) — parse withstrptime/new Date()for the final check. - GA4's own date fields are always ISO
YYYY-MM-DD— for GA4 filters use the ISO date pattern, not this one.
FAQ
How do I validate mm/dd/yyyy in JavaScript?
const US = /^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/[0-9]{4}$/; then US.test('12/31/2026'). Both parts are zero-padded and range-limited.
How can I tell if a date is US or European format?
You cannot from the numbers alone when day ≤ 12 — 04/05/2026 is legal in both systems. Use the data source's locale, or normalize everything to ISO YYYY-MM-DD at ingestion.
What regex matches both US and European slash dates?
^(0[1-9]|1[0-2]|[12][0-9]|3[01])/(0[1-9]|1[0-2]|[12][0-9]|3[01])/[0-9]{4}$ — either order in either slot, meaning resolved in code. Prefer writing ISO instead.
Related patterns
Regex to Match Date (YYYY-MM-DD) — Test & Copy · ISO 8601 DateTime Regex — Match & Test Online · Extract Numbers from String — Regex + Examples
For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.