PatternRegex
Validate a card expiry (MM/YY)
Check a card's MM/YY expiry field for a real month, 01 through 12, followed by a two-digit year — nothing else.
Last updated
Matches
- 01/25
- 12/99
- 09/30
Doesn’t match
- 13/25
- 00/25
- 1/25
Why it’s written this way
The month is checked by an alternation: (?:0[1-9]|1[0-2]) accepts 01 through 09 via the first branch and 10 through 12 via the second — a plain \d{2} would let '00' or '13' through, and no card ever expires in either.
The slash needs no escaping in a string-built RegExp, so /\d{2} simply requires exactly two digits for the year, and the surrounding anchors stop a stray extra character after '25' from sneaking past.
Edge cases to know
- →It accepts any two-digit year, including ones already in the past — pairing the regex with an actual date comparison is still necessary to catch an expired card.
- →It only recognizes the MM/YY layout; a field that also accepts MM/YYYY or 'MM-YY' needs a different pattern entirely.
- →Century assumptions live outside the regex — '25' has to be resolved to 2025 by your own logic, which eventually needs a decision about where the rollover point sits.