Parse, format, and validate credit card data.
npm install --save creditcardscreditcards exports:
cardcvcexpiration
Remove all non-numeric characters from a card number, including punctuation and spacing.
Required
Type: string
Formats a card number as printed on the physical card
Required
Type: string
Type: string
Default: ' ' (space)
card.format('4242424242424242') === '4242 4242 4242 4242' // Visa
card.format('378282246310005') === '3782 822463 10005' // American ExpressReturns the matched card type, or undefined if there was no match. For a full list of supported card types, see creditcards-types.
Required
Type: string
The card number. Punctuation is not allowed. Sanitize input through card.parse first if needed.
Type: boolean
Default: false
When true, the card type will be eagerly matched using a more permissive pattern that can match partial card numbers.
Checks the card number's validity using the Luhn algorithm.
Required
Type: string
Required
Type: string
Type: string
Default: undefined
Detect if a card is a valid card of the specified type. If no type is provided, the card will be valid if any type is matched.
Required
Type: string
Type: string
Default: undefined
Detect if a CVC is valid card for the specified type.
Required
Type: number
Required
Type: number
Casts the provide value a number. All of the following will be 5 after parsing:
5'05''5'
Required
Type: string / number
Required
Type: number
All of the following are equivalent:
expiration.year.parse(2014)expiration.year.parse('2014')expiration.year.parse('14', true)expiration.year.parse(14, true)
Required
Type: string / number
Type: boolean
Default: false
If true, the year is assumed to be a 1 or 2 digit number and is expanded to its full value.
Required
Type: number
Type: boolean
Default: false
If true, year is assumed to be a four digit number and will be converted to a two digit number.
expiration.year.format(2014) === '2014'expiration.year.format(2014, true) === '14'
Required
Type: number
Required
Type: number
MIT © Ben Drucker