isCvvValid static method

bool isCvvValid(
  1. String cvv,
  2. CardType cardType
)

Pass card cvv and it will return its likely validity.

This function checks if the cvv contains only digits and if its length matches the given issuing network.

cvv The cvv to validate

cardType The issuing network to validate against

var cvv = "123";
var visaCvvIsValid = FlutterCardidy.IsCvvValid(cvv, CardType.Visa);

returns True if it seems alright, else false.

Implementation

static bool isCvvValid(
  String cvv,
  CardType cardType,
) {
  return cardType != CardType.Unknown &&
      (cvv.runes.every((element) => element.isDigit())) &&
      (cardType == CardType.AmericanExpress
          ? cvv.length == 4
          : cvv.length == 3);
}