identify static method
Pass card number and it will return list of matching issuing network, if found.
cardNumString
The card number to identify.
validateLength
Validate the length as part of the String identification.
A false value can be useful to identify the fragment of a card number.
Default is true.
useCheck
Validate the card number as part of the String identification.
A false value can be useful to identify the fragment of a card number.
The validation will be the issuing network's validation, mostly Luhn.
Default is true.
ignoreNoise
Ignore common noise found in card number.
This noise is any of - .
. Default is false.
handleAnonymization
Set any non-digits to zero.
It is common to use "X" and "#" to hide some digits. Default is false.
var card = "4771320594033";
var identifiedCards = FlutterCardidy.Identify(card);
var isVisa = identifiedCards.isNotEmpty ?
identifiedCards.first == CardType.Visa : false;
returns List<CardType> list of issuing network identified
.
Implementation
static List<CardType> identify(
String cardNumString, {
bool validateLength = true,
bool useCheck = true,
bool ignoreNoise = false,
bool handleAnonymization = false,
}) {
if (!cardNumString.isCardNumberValid(handleAnonymization, ignoreNoise)) {
return List<CardType>.empty();
}
var digits = cardNumString.toDigits(ignoreNoise: ignoreNoise);
var identificationNumber = digits
.take(_identificationNumberLength)
.toList()
.toNumber()
.padRight(_identificationNumberLength, 0);
var isStrict = validateLength && !handleAnonymization;
return _knownCards
.where((knownCard) => knownCard.prefixes.any((prefix) =>
prefix.contains(identificationNumber) &&
(!validateLength || knownCard.lengths.contains(digits.length)) &&
(!useCheck || isStrict && knownCard.check(digits))))
.map((x) => x.name)
.toList();
}