Validating Credit Card Numbers With Pure JavaScript – credicard.js

Category: Form , Javascript | May 25, 2018
Author: ContaAzul
Views Total: 4,007
Official Page: Go to website
Last Update: May 25, 2018
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.

How to use it:

To get started, you need to 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'));

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:

v2.1.5 (05/25/2018)

  • Update CREDIT_CARD_LIST to use literal regex

You Might Be Interested In:


Leave a Reply