Card Expiry Date (MM/YY or MM/YYYY) Regex for JavaScript
/^(0[1-9]|1[0-2])/(?:20[0-9]{2}|[2-9][0-9])$/What this pattern does
This page provides a well-structured, multi-part regular expression for matching card expiry date (mm/yy or mm/yyyy), ported and verified for JavaScript. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. 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
// Card Expiry Date (MM/YY or MM/YYYY)
// ReDoS-safe | RegexVault — Finance > Card Numbers
const cardExpiryDateMmyyOrMmyyyyRegex = /^(0[1-9]|1[0-2])\/(?:20[0-9]{2}|[2-9][0-9])$/;
function validateCardExpiryDateMmyyOrMmyyyy(input: string): boolean {
return cardExpiryDateMmyyOrMmyyyyRegex.test(input);
}
// Example
console.log(validateCardExpiryDateMmyyOrMmyyyy("01/24")); // trueTest Cases
Matches (Valid) | Rejects (Invalid) |
|---|---|
01/24 | 00/24 |
12/29 | 13/24 |
06/2025 | 1/24 |
01/2099 | 01/24/00 |
| — | 01-24 |
| — | 01/9 |
| — | 01/199 |
When to use this pattern
This pattern is drawn from the Finance > Card Numbers 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
A card expires at the end of the expiry month (not the 1st). 06/24 is valid until June 30, 2024 23:59:59. Do not reject on the expiry month's first day.
Technical Notes
Capture group 1: month (01-12), group 2: year (2-digit or 4-digit). 2-digit years in the range 20-99 map to 2020-2099. Cards expired but still within the grace period may still be valid — check against today's date at application level.
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