Validating Credit Card Numbers With Pure JavaScript – credicard.js

Category: Form , Javascript | June 2, 2021
Author: ContaAzul
Views Total: 62 views
Official Page: Go to website
Last Update: June 2, 2021
License: MIT

Preview:

Validating Credit Card Numbers With Pure JavaScript – credicard.js

Description:

credicard.js is a zero-dependency JavaScript library for validating credit card number, expiration date, security code and returning the credit card brand.

Supports both browser and server.

Supported Credit Card Types:

  • American Express
  • Aura
  • Banescard
  • Cabal
  • Diners
  • Discover
  • Elo
  • Goodcard
  • Hipercard
  • Mastercard
  • Maxxvan
  • Visa

How to use it:

Install & import the credicard.js component.

# NPM
$ npm i creditcard.js
import { 
  isValid, 
  isExpirationDateValid, 
  isSecurityCodeValid, 
  getCreditCardNameByNumber 
} from 'creditcard.js';

Or include the credicard.js script on your webpage.

<script src="creditcard.js"></script>

Validate a specified credit card number.

var creditcard = new CreditCard();
// return true
console.log(creditcard.isValid('4111111111111111'));
isValid('4916108926268679', { cards: ['visa', 'mastercard'] }) // returns true
isValid('4916108926268679', { cards: ['mastercard'] }) // returns false

Validate the expiration date.

var creditcard = new CreditCard();
// return true
console.log(creditcard.isExpirationDateValid(''05', '2020''));

Validate the security code.

var creditcard = new CreditCard();
// return true
console.log(creditcard.isSecurityCodeValid(''4111111111111111', '250''));

Validate a specified credit card number and return the result in the console.log.

var creditcard = new CreditCard();
// return 'Visa'
console.log(creditcard.getCreditCardNameByNumber('4111111111111111'));

Changelog:

v3.0.10 (06/02/2021)

  • update devDependencies

v3.0.7 (05/13/2021)

  • update devDependencies

v3.0.6 (03/23/2021)

  • applying single responsability into isValid function

v3.0.5 (02/26/2021)

  • IsValid card options

v3.0.3 (01/21/2021)

  • Bug Fixes

v3.0.0 (01/18/2021)

  • v3

v2.1.5 (05/25/2018)

  • Update CREDIT_CARD_LIST to use literal regex

You Might Be Interested In:


Leave a Reply