ContaAzul / creditcard.js

A simple credit card validation library in JavaScript
http://contaazul.github.io/creditcard.js/
Other
374 stars 82 forks source link

Error when is send cardNumber null param on isSecurityCodeValid method #126

Closed dedicio closed 3 years ago

dedicio commented 3 years ago

Want to request a feature or report a bug?

Report a bug

What is the current behavior?

When it sends param creditCardNumber = null in isSecurityCodeValid methods, it generates a console error image

The problem is: try to replace from a null value on line 33: const numberOnly = number.replace(/[^\d]/g, '');

Suggestion:

export const isSecurityCodeValid = (creditCardNumber, securityCode) => {
  if (!creditCardNumber || !securityCode) return false;
  const numberLength = getCreditCardCodeLengthByNumber(creditCardNumber);
  return new RegExp(`^[0-9]{${numberLength}}$`).test(securityCode);
};

What is the expected behavior?

The method isSecurityCodeValid returns false when send any null param