Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afzalimdad9/card-validator
Card validation helpers for payment forms.
https://github.com/afzalimdad9/card-validator
amex card card-validator credit-card mastercard payments rupay visa
Last synced: about 2 months ago
JSON representation
Card validation helpers for payment forms.
- Host: GitHub
- URL: https://github.com/afzalimdad9/card-validator
- Owner: afzalimdad9
- License: mit
- Created: 2024-08-26T08:37:52.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-08-26T14:45:14.000Z (4 months ago)
- Last Synced: 2024-10-29T00:57:13.888Z (2 months ago)
- Topics: amex, card, card-validator, credit-card, mastercard, payments, rupay, visa
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Card Validator
Generic helpers for card number, expiry and CVV validations
[![npm version](https://badge.fury.io/js/%40afzalimdad9%2Fsimple-card-validator.svg)](https://badge.fury.io/js/%40afzalimdad9%2Fsimple-card-validator)
## Usage:
Import the library and initialize card object.Install from npm:
`npm i @afzalimdad9/simple-card-validator --save`
`var cardValidator = require('simple-card-validator');`
Or, you can simply use the file from `dist/validator.js` if you are not using node/npm.
`var card = new cardValidator('4242-4242-4242-4242');`
### Getting card details
`card.getCardDetails();`
This would output, card brand and different validation outputs like below:
```
{
card_type: 'visa',
valid: true,
luhn_valid: true,
length_valid: true,
cvv_length: [3],
gaps: [4, 8, 12],
supported_lengths: [16],
max_length: 16
}
```#### Output format
| Field | Description | Type |
| ----------------- | ------------------------------------- | ----------------- |
| card_type | The card issuer for the provided card | String |
| valid | Are the card details valid | Boolean |
| luhn_valid | Is the card number valid | Boolean |
| length_valid | If the card number length is valid | Boolean |
| cvv_length | If the CVV/CAVV length is valid | Array [ Integer ] |
| gaps | Gaps for UI as printed in cards | Array [ Integer ] |
| supported_lengths | Supported lengths for the card type | Array [ Integer ] |
| max_length | Maximum length for the card type | Integer |### Validations
To simply validate a card, call:
`card.validateCard();`
The result will be a validity boolean.For validating expiry date,
`card.validateExpiry('12/2018');`Additionally, the base date can be set for expiry validations. The base month and date can be provided by using,
`card.setBaseDate(month, year);`eg: `card.setBaseDate('02', '2016');`
For validating CVV, use:
`card.validateCvv(111);`
CVV will be validated based on the brand of the card.## License
MIT license. Copyright © 2024 - [afzalimdad9](https://afzalimdad9.vercel.app).