A simple library built around https://github.com/medipass/react-payment-inputs that exposes its validation in more convienent APIs.
⚠️ This library is still in its alpha stage development and isn't stable.
yarn add https://github.com/vivait/card-validator
import { predictPaymentNetworkForAccountNumber } from 'vivait-card-validator';
Predict a card type and other relevant information based on its primary account number.
Property | type | description |
---|---|---|
recognised |
boolean |
If the type of card was matched against the database. |
displayName |
string |
A friendly name for the payment network. |
type |
'visa' | 'mastercard' | 'amex' | 'dinersclub'| 'discover' | 'jcb' | 'unionpay' | 'maestro' | 'elo' | 'hipercard' | 'unknown' |
A computer name for the payment network. |
format |
RegExp |
The format of the primary account number. |
startPattern |
RegExp |
The format for the first digits to |
gaps |
number[] |
Places in the primary account number where there are spaces to assist with copying from the card. |
lengths |
number[] |
Valid lengths for the primary account number. |
code.name |
string |
Name of the payment network's security number. |
code.length |
number[] |
Valid lengths for the network's security number. |
primaryAccountNumberMaskFormat |
string |
String formatted like 'nnnn nnnn nnnn nnnn' for the primary account number. |
import { isValidCreditCard } from 'vivait-card-validator';
Checks if the entire primay account number is valid, checks using the luhns algorithm and the length of the card number.