1001Ferramentas
💳Validators

CC Expiry Validator

Validate a credit card expiry date in MM/YY format, checking the month and whether it has not expired. Useful for payment forms and checkout flows.

MM/YY and the last valid day

At checkout, the expiry field is where customers slip the most: they type 1/28, they type 12/2028, they swap month and year. And there is the question that resurfaces in every code review: does a card marked 07/26 still work on 26 July 2026? It does. A card is good through the last day of the printed month, and treating the current month as expired kills payments that were perfectly fine.

The check has two halves. The format is strict: two digits, a slash, two digits, with the month between 01 and 12. No 1/28, no 12/2028, no 12-28, and that is deliberate, since it matches what card terminals and most payment forms expect to receive. Then comes the comparison against your device date, where the current month still counts as valid and only months already behind get rejected.

Two things to keep in mind. The two digit year is read as belonging to this century, so 12/99 comes back valid in the sense of 2099, and a card from 1999 would land on the same answer. Nobody types that in practice, but it explains where the verdict comes from. And the clock is the one on the machine doing the testing, not the server, so a wrong system date changes the result. This checks the expiry only; the card number needs a separate Luhn check, and nothing is sent anywhere.

Frequently asked questions

Does a card marked 07/26 work in July 2026?
Yes. The expiry runs through the last day of the printed month, so the card stays valid for that whole month and only lapses when the next month starts.
Why is 12/2028 reported as invalid?
Because the accepted format is MM/YY with a two digit year. Write 12/28. The rule is strict on purpose, to mirror what payment forms usually require.
Does this validate the card number?
No. It only checks the expiry field, its format and whether it has passed. For the number itself, use a Luhn algorithm validator, which is a separate check.

Related Tools