JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 227
  • Score
    100M100P100Q83647F
  • License MIT

Credit Card validation using luhn algorithm

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.

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 : ''  // Helpful message to indicate why the Card is invalid
}

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 isValid = require('cc-validate');
var 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'  // Helpful message to indicate why the Card is invalid
}

TypeScript

import { isValid } from 'cc-validate';
let valid = 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' // Helpful message to indicate why the Card is invalid
}

Test

npm run test