isCreditCard
isCreditCard :: a โ Boolean
Reports whether the received value is a valid credit card number.
import isCreditCard from 'deep-waters/isCreditCard';
isCreditCard(347190259623701); // American Express โ true
isCreditCard(4286124395547263); // VISA โ true
isCreditCard(5276023546902691); // Mastercard โ true
isCreditCard(6011583945260254); // Discover โ true
isCreditCard(38716394960899); // Diners Club โ true
isCreditCard(3528701379615495); // JCB โ true
isCreditCard('6011-5839-4526-0254'); // Credit card format โ false
isCreditCard("foo"); // โ false
isCreditCard(undefined); // โ false
Please note, isCreditCard assumes the receiving value is a number or a string without the usual dashes. It only evaluates the credit card number, not its format.
Specificity
isCreditCard reports whether a string or a number is a valid credit card number, it doesn't tell anything on the type of card. To check on specific card types it's possible to use one of the composing function of isCreditCard:
Last updated
Was this helpful?