creditcard-checkerjs

1.2.0 • Public • Published

CreditCard-Checker.js

This is a simple module that verifies the checksum of credit card numbers and detects international brands from credit card numbers.

Currently, the following international brands are supported.

  • VISA
  • Master Card
  • JCB
  • American Express (AMEX)
  • Diners Club

Install

$ npm install creditcard-checkerjs

Example

Node.js

const creditcard = require('creditcard-checkerjs')
const number = '4111111111111111'

//---------------------------------------
// checksum and check cardnumber length
//---------------------------------------
if( creditcard.check(number) ){
  console.log('correct!')
}
else{
  console.log(`incorrect! ${creditcard.getError().message}`)
}

//---------------------------------------
// Only checksum
//---------------------------------------
if( creditcard.verify(number) ){
  console.log('valid')
}
else{
  console.log('invalid')
}

//---------------------------------------
// Detect card brand
//---------------------------------------
const type = creditcard.cardtype(number)
switch( type ){
  case creditcard.type.VISA:
      console.log('Visa');
      break;
  case creditcard.type.MASTER:
      console.log('Mastercard');
      break;
  case creditcard.type.JCB:
      console.log('JCB');
      break;
  case creditcard.type.AMEX:
      console.log('American Express');
      break;
  case creditcard.type.DINERS:
      console.log('Diners');
      break;

  case creditcard.type.UNKNOWN:
  default:
      console.log('Unknown');
      break;
}

Web Browser

<script src="dist/creditcard-checker.min.js"></script>
<script>
const number = '4111111111111111'

if( creditcard.check(number) ){
  console.log('correct!')
}
else{
  console.log(`incorrect! ${creditcard.getError().message}`)
}
</script>

Licence

MIT License

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.042latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.042
1.1.00
1.0.00

Package Sidebar

Install

npm i creditcard-checkerjs

Weekly Downloads

42

Version

1.2.0

License

MIT

Unpacked Size

20.7 kB

Total Files

14

Last publish

Collaborators

  • katsube