[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Credit card expiry date validation
- From: "Joseph C. Sible" <josephcsible@...>
- Date: Mon, 15 Jun 2020 17:26:33 -0400
On Mon, Jun 15, 2020 at 4:15 PM Wilmar Pérez <firstname.lastname@example.org> wrote:
> I have an application collecting credit card data. Before sending the information out to the payment entity I am trying to make sure the information entered is, at least, valid. I already worked out the card number and cvv numbers but I am not so sure about the expiry date. The format I get the info is MMYY.
> -- Extract the last two digits of the Year
> current_year = string.sub(current_year , 3, 4)
> (card_exp_year < current_year) or (card_exp_year == current_year and card_exp_month < current_month)
> I do not know if this is the most elegant solution but it works. However it has a huge bug: it will fail at the end of the century. Since I only know the last two digits of the expiry date year, if a card expires in 2102 for instance and we were in 2099 my logic would wrongly reject the date (02 is less than 99).
You need to make an assumption: one possibility is to assume that no
credit card will be valid for more than 50 years, and that nobody will
try to use a credit card that's been expired for more than 50 years.
You can then replace your "card_exp_year < current_year" check with
"(card_exp_year - current_year) % 100 < 50".
Joseph C. Sible