americanExpressCard static method

bool americanExpressCard(
  1. String cardNumber
)

Validates whether the given cardNumber is a valid American Express card number.

The cardNumber parameter should be a string representing an American Express card number.

Returns true if the cardNumber is valid, false otherwise.

Implementation

static bool americanExpressCard(String cardNumber) {
  String pattern = r'^3[47][0-9]{13}$';
  RegExp regExp = RegExp(pattern);
  return regExp.hasMatch(cardNumber);
}