ISO 8601 Week Date (YYYY-Www-D) Regex for JavaScript
/^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching iso 8601 week date (yyyy-www-d), ported and verified for JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.
Javascript Implementation
// ISO 8601 Week Date (YYYY-Www-D)
// ReDoS-safe | RegexVault — Localization > Date Formats
const iso8601WeekDateYyyywwwdRegex = /^((?:19|20)[0-9]{2})-W(0[1-9]|[1-4][0-9]|5[0-3])(?:-([1-7]))?$/;
function validateIso8601WeekDateYyyywwwd(input: string): boolean {
return iso8601WeekDateYyyywwwdRegex.test(input);
}
// Example
console.log(validateIso8601WeekDateYyyywwwd("2024-W03")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
2024-W03 | 2024-W00 |
2024-W03-1 | 2024-W54 |
2024-W52-7 | 2024-W03-0 |
2020-W53 | 2024-W03-8 |
2024-W01-5 | 2024W03 |
| — | 2024-W3 |
When to use this pattern
This pattern is drawn from the Localization > Date Formats category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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
ISO week year ≠ calendar year at year boundaries. 2024-W01-1 (Monday of week 1 of 2024) is actually December 31, 2023 in the calendar. Use isoweek-aware date libraries.
Technical Notes
ISO week year may differ from calendar year — the first week of the year contains the first Thursday. Week 1 starts from Monday. Day: 1=Monday, 7=Sunday. Some years have 53 weeks (ISO 8601 long years).
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