Tag Archives: creditcard

JavaScript

Announcing card.js

I would like to announce card.js!

It is brand new library with following features:

  • Credit card type detection based on IIN number. See more on wikipedia.
  • Credit card type detection for full length card number
  • Luhn algorithm validation. See more on wikipedia.

How to use it?

It can be loaded via a script tag in a HTML document for the browser (check examples/browser)

<script src='./relative/path/to/card.js'></script>

or as a CommonJS module.

For Node, put the card.js file into the same directory as the file that is requiring it and use

var card = require('./card.js');

or put it in a node_modules directory within the directory and use require(‘card.js’). See example in examples/nodejs.

The library is also available from the npm registry, so

$ npm install card.js

will install this library in a node_modules directory within the current directory.

Example of usage

card('4111111111111111').getType(); // output: visa
card('41').getIINType(); // output: visa
card('4111111111111111').isValid(); // output: true

Supported browsers:

  • Chrome
  • Firefox
  • Internet Explorer 9
  • Safari
  • Opera

Supported card types:

Issuing network card type returned by getType
Visa visa
Mastercard mastercard
American Express amex
Maestro meastro
Diners Club diners
Discover discover
JCB jcb
UATP uatp
InterPayment interpayment
InstaPayment instapayment
China UnionPay unionpay
Dankort dankort