https://github.com/ContaAzul/creditcard.js
A simple credit card validation library in JavaScript
https://github.com/ContaAzul/creditcard.js
credit-card javascript nodejs validation
Last synced: about 2 months ago
JSON representation
A simple credit card validation library in JavaScript
- Host: GitHub
- URL: https://github.com/ContaAzul/creditcard.js
- Owner: ContaAzul
- License: other
- Created: 2016-01-25T15:39:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-04-14T12:28:42.000Z (3 months ago)
- Last Synced: 2025-04-14T13:23:52.561Z (3 months ago)
- Topics: credit-card, javascript, nodejs, validation
- Language: JavaScript
- Homepage: http://contaazul.github.io/creditcard.js/
- Size: 2.13 MB
- Stars: 378
- Watchers: 57
- Forks: 82
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-made-by-brazilians - creditcard.js
README
# creditcard.js
[](https://github.com/ContaAzul/creditcard.js/actions?query=workflow%3A%22Build+Check%22)

[](https://www.npmjs.com/package/creditcard.js)> 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
```sh
yarn add creditcard.js
```### NPM
```sh
npm install creditcard.js
```## Usage
```javascript
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](#suportted-credit-card-types))_
**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](#supported-credit-card-types))_
**number**
_Required_\
Type: `string`---
## Supported credit card types
- American Express
- Aura
- Banescard
- Cabal
- Diners
- Discover
- Elo
- Goodcard
- Hipercard
- Mastercard
- Maxxvan
- Visa## Credits
The first version of this library was based on [bin-cc](https://github.com/renatovico/bin-cc).
## License
MIT © Conta Azul