Skip to content

Latest commit

 

History

History
122 lines (79 loc) · 2.41 KB

README.md

File metadata and controls

122 lines (79 loc) · 2.41 KB

creditcard.js

Build Status Dependency Status devDependency Status npm

A simple credit cards validation library in JavaScript.

Project website: https://contaazul.github.io/creditcard.js

Install

creditcard.js is available as a NPM package. You can install through Yarn or NPM:

Yarn

$ yarn add creditcard.js

NPM

$ npm install creditcard.js

Usage

import {
  isValid,
  isExpirationDateValid,
  isSecurityCodeValid,
  getCreditCardNameByNumber,
} from 'creditcard.js';

isValid('4916108926268679'); // returns true
isExpirationDateValid('02', '2020'); // returns true
isSecurityCodeValid('4556603578296676', '250'); // returns true
getCreditCardNameByNumber('4539578763621486'); // returns 'Visa'

Methods

isValid(number) -> boolean

Checks whether the credit card number format is valid. (See the full list of currently supported cards)

number

Required
Type: string

options

Optional
Type: { cards: string[] }


isExpirationDateValid(month, year) -> boolean

Checks that the expiration date is valid and not expired. (2 or 4 digit years are accepted)

month

Required
Type: string

year

Required
Type: string


isSecurityCodeValid(creditCardNumber, securityCode) -> boolean

Check that the security code is valid according to the type of credit card.

creditCardNumber

Required
Type: string

securityCode

Required
Type: string


getCreditCardNameByNumber(number) -> string

Returns the credit card type from the card number. (See the full list of currently supported cards)

number

Required
Type: string


Suportted credit card types

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

License

MIT © Conta Azul