Returns credit card type given a number

Usage no npm install needed!

<script type="module">
  import sCreditcard from 'https://cdn.skypack.dev/s-creditcard';



NPM version Dependencies build status NPM license


npm install --save s-creditcard


Input a credit card number (as a string) and it returns the type of credit card. Incomplete inputs will also return successfully for the following card types:

  • visa
  • amex
  • mastercard
  • discover
  • jcb
card('4242424242424242') // returns 'visa'
Supported card types
  • Visa (visa)
  • Mastercard (mastercard)
  • Discover (discover)
  • American Express (amex)
  • Diners Club (dinersClub)
  • JCB (jcb)
  • Carte Blanche (carteBlanche)
  • Unionpay (unionpay)
  • Lasercard (lasercard)
  • Solo (solo)
  • Maestro (maestro)

All other valid credit cards return other. Invalid credit cards return none. Be sure to trim whitespace and remove non-numeric characters from the credit card number.