Package Exports
- cc-validate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cc-validate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 = {
cardNumber : "4111 1111 1111 1111", // Formatted credit card string
cardType : 'Visa', // credit card Type
isValid : true, // Boolean True if card is valid, false if it is invalid
message : '' // Success/Failure message
}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 --saveUsage
Javascript
var validate = require('cc-validate');
var result = validate.isValid('4196221438170266');
result = {
cardNumber : "4196 2214 3817 0266", // Formatted Credit Card String
cardType : 'Visa', // Credit Card Type
isValid : true, // Boolean True if card is valid, false if it is invalid
message : 'Credit Card number entered valid' // Success/Failure message
}TypeScript
import { isValid } from 'cc-validate';
let result = isValid('4196221438170266');result = {
cardNumber : "4196 2214 3817 0266", // Formatted Credit Card String
cardType : 'Visa', // Credit Card Type
isValid : true, // Boolean True if card is valid, false if it is invalid
message : 'Credit Card number entered valid' // Success/Failure message
}Test
npm run testMajor 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