Skip to content

Credit/debit card validation for browsers and Node.js, uses the Luhn algorithm and pattern matching.

License

Notifications You must be signed in to change notification settings

theninja/credit-card-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Credit Card Validation

This is a micro-library for credit card validation. It checks a card number is valid and detects the issuing bank (IIN). It currently supports most major card issuers.

Try the example at http://theninja.github.io/credit-card-validation/.

Import

Browser

Simply add the script (<script src="card.min.js"></script>) either just before the closing body tag or within the head of your page.

var card = CardValidate('xxxxxxxxxxxxxxxx');

Node.js

var cardvalidate = require('card'),
	card = cardvalidate('xxxxxxxxxxxxxxxx');

Usage

At the moment the script is purposefully simple and exposes only two public methods.

// returns default if unkown or the issuing bank's name (lowercase)
card.getType();
// returns true if the card is validated by Luhn algorithm
// and matches card requirements or false if not
card.isValid();

Testing

To run tests simply run npm install if you haven't already, followed by npm test.

##TODO

Possibly add CVC length and expiration date checks.

Disclaimer

This doesn't check that a credit card is real or that payment can be made with it. The Luhn algorithm is easily fooled as it's a simple mathematical formula, this just helps avoid typos and typical user errors. The only way to check if a card is actually valid (including CVC etc.), is by using a real payment provider that offers this service.

Licensing

The code is MIT licensed.

The trademarks and branding included in this project, namely those of the credit card providers, are property of their respective owners.

About

Credit/debit card validation for browsers and Node.js, uses the Luhn algorithm and pattern matching.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published