REGEXVAULTv2.0
Finance/Card Numbers
Verified Safe

Card Expiry Date (MM/YY or MM/YYYY) Regex for PHP

/^(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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// Card Expiry Date (MM/YY or MM/YYYY)
// ReDoS-safe | RegexVault — Finance > Card Numbers

define('CARD_EXPIRY_DATE_MMYY_OR_MMYYYY_PATTERN', '/^(0[1-9]|1[0-2])\/(?:20[0-9]{2}|[2-9][0-9])$/');

function validate_card_expiry_date_mmyy_or_mmyyyy(string $input): bool {
    return (bool) preg_match(CARD_EXPIRY_DATE_MMYY_OR_MMYYYY_PATTERN, $input);
}

// Example
var_dump(validate_card_expiry_date_mmyy_or_mmyyyy("01/24")); // bool(true)

Test Cases

Matches (Valid)
Rejects (Invalid)
01/2400/24
12/2913/24
06/20251/24
01/209901/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 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

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