basics · 2025-02-10 · 5 min read
Expiry dates: valid through the last day of the month
A card marked 05/30 works until 23:59 on 31 May 2030. Small detail, common bug — and one of several traps in a field that looks trivial.

The expiry printed on a card is a month and a two-digit year. The card remains valid through the final day of that month, so validation must compare against the end of the month, not its start. Our inspection bench applies exactly this rule — try 01/26 versus the current month to see the difference.
The end-of-month rule in code
Build a date for the first day of the following month and check that now is earlier than it. Equivalent: new Date(year, month, 0, 23, 59, 59) in JavaScript gives the last second of the expiry month because day 0 of the next month rolls back.
Edge cases worth a unit test
- Two-digit years: 30 means 2030. Decide explicitly what 99 means; most libraries assume the current century.
- Month 00 or 13: reject with a clear message, not a generic 'invalid'.
- Time zones: the issuer evaluates expiry in its own zone; a card may be accepted a few hours after your local midnight.
- Dates more than ~20 years out are almost always typos — warn, don't block.
- Expiring this month is valid but worth a soft notice for subscriptions.
Formatting and autofill
Accept 4 digits and insert the slash automatically, keep the caret stable, and set autocomplete="cc-exp" (or cc-exp-month / cc-exp-year) so browsers and password managers can fill the field — the MDN autocomplete reference lists the tokens. More on input ergonomics in formatting as you type.
An unexpired date proves nothing about the account. Like Luhn, it is a typo filter; the issuer's authorization is the real check.

Keywords: card expiry date, expiration date validation, MM/YY, end of month, cc-exp autocomplete, expired card
Frequently asked questions
Is a card valid on the last day of its expiry month?
Yes. A card marked 05/30 is valid through 31 May 2030 and expires at the start of June.
What autocomplete value should an expiry field use?
cc-exp for a combined MM/YY field, or cc-exp-month and cc-exp-year for separate fields.