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