Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/utils/credit_card_util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

const date = new Date();
const currentYear = date.getFullYear();
const currentMonth = date.getMonth() + 1;

function CreditCardUtil() {}

var CYBCardTypes = {
Expand All @@ -23,12 +27,19 @@ CreditCardUtil.isCreditCardNumberValid = function (creditCardNumber) {
};

CreditCardUtil.isCreditCardExpirationDateValid = function (cardExpirationMonth, cardExpirationYear) {
return NUMBER_REGEX.test(cardExpirationMonth) &&
NUMBER_REGEX.test(cardExpirationYear) &&
Number(cardExpirationMonth) >= 1 &&
Number(cardExpirationMonth) <= 12 &&
Number(cardExpirationYear) >= 2016 &&
Number(cardExpirationYear) <= 2100;
if (
!NUMBER_REGEX.test(cardExpirationMonth) ||
NUMBER_REGEX.test(cardExpirationYear)
) return false; // check if input is number

const expMonth = Number(cardExpirationMonth);
const expYear = Number(cardExpirationYear);
return (
expYear >= currentYear &&
expYear <= 2100 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imajindev could you mind changing into something like this

Suggested change
expYear <= 2100 &&
expYear <= currentYear + 100

expMonth <= 12 &&
expMonth >= currentMonth
); // check if valid value range
};

CreditCardUtil.isCreditCardCVNValid = function (creditCardCVN) {
Expand Down