isValidCardNumber static method

bool isValidCardNumber(
  1. String cardNumber
)

Validate card number format and Luhn algorithm.

Performs two validations:

  1. Format check: 13-19 digits only
  2. Luhn algorithm check: Mathematical validation for card number integrity

Parameters

  • cardNumber: The card number to validate (digits only, no spaces)

Returns

true if the card number is valid, false otherwise.

Implementation

static bool isValidCardNumber(String cardNumber) {
  if (!_cardNumberRegex.hasMatch(cardNumber)) return false;
  return _luhnCheck(cardNumber);
}