isExpiryValid static method

bool isExpiryValid(
  1. String? expirationMonth,
  2. String? expirationYear
)

Determines whether the card expiration month and year are valid

@param expirationMonth The month a card expired represented by digits (e.g. 12) @param expirationYear The year a card expires represented by digits (e.g. 2026) @return true if both the expiration month and year are valid

Implementation

static bool isExpiryValid(String? expirationMonth, String? expirationYear) {
  if (expirationMonth == null || expirationYear == null) {
    return false;
  }

  String cleanMonth = _removeWhitespace(expirationMonth);
  String cleanYear = _removeWhitespace(expirationYear);

  return _isNumeric(cleanMonth) &&
      _isNumeric(cleanYear) &&
      _number(cleanMonth) >= 1 &&
      _number(cleanMonth) <= 12 &&
      _number(cleanYear) >= 2017 &&
      _number(cleanYear) <= 2100 &&
      _isNotInThePast(cleanMonth, cleanYear);
}