validation
ISO 8601 Date (YYYY-MM-DD) Regex Pattern
Validates ISO 8601 date format (YYYY-MM-DD). Checks month (01-12) and day (01-31) ranges. Does NOT check that the day is valid for that month (Feb 31 would pass) — for calendar validation, use JS Date.
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/ What each part matches
^\d{4} — 4-digit year-(0[1-9]|1[0-2])- — month 01-09 OR 10-12(0[1-9]|[12]\d|3[01])$ — day: 01-09 OR 10-29 OR 30-31✓ These match
- 2026-04-16
- 1999-12-31
- 2000-02-29
✗ These don't
- 2026-13-01
- 2026-04-32
- 26-04-16
- 2026/04/16
Use in your code
JavaScript
const re = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
re.test(input); // → true or false Python
import re
re.fullmatch(r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$", input) PHP (PCRE)
preg_match('/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/', $input); Go
re := regexp.MustCompile(`^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`)
re.MatchString(input) FAQ
Does this iso 8601 date (yyyy-mm-dd) regex work in JavaScript?
Yes. Every pattern in the Utilko regex library is tested to work in JavaScript RegExp, PCRE (PHP, Nginx), and Python `re`. Where flavor matters (lookbehind, named groups), the pattern page flags it.
How do I use this pattern?
Copy the pattern from the code block above. In JavaScript:
new RegExp('^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$') or literal /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/. Or click "Try in regex tester" to open it pre-loaded in Utilko's browser-based regex tester.Should I use this for security-critical validation?
Client-side regex is fine for UX (immediate feedback on a form). For anything security-critical — payments, auth, data integrity — always re-validate server-side using the same pattern PLUS domain-specific checks (Luhn checksum for cards, actual email delivery test, DNS resolution for domains).