Credit Card Validation
A credit card validation package that is based on luhn algorithm with some small additions to cover the loopholes of this algorithm.
Supported credit card types
- Visa
- MasterCard
- AMEX
- Discover
- JCB
- Diners Club
Demo
https://cc-validate.firebaseapp.com/
Input
Pass the credit card number as a string var result = isValid('4111111111111111');
Output
An object
result =
A detailed explanation of how the underlying algorithm works can be found in this article : https://link.medium.com/FZZwZ0YyXX
A typical use case in a credit card form to notify the user if the credit card number is entered is invalid
Download
You can install card-validator
through npm
.
Installation
npm install cc-validate --save
Usage
Javascript
var validate = ;var result = validate;
result =
TypeScript
;;
result =
Test
npm run test
Major and Recent Changes
V 2.0.5 : Added live demo link
V 2.0.4 : Added validation for Diners Club
V 2.0.0 : Addition of credit card type validation and card number formatting
V 1.0.9 First Stable Version