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.


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:
Copy link