isValidExpiryBool static method

bool isValidExpiryBool(
  1. String? value
)

Implementation

static bool isValidExpiryBool(String? value) {
  final inputValue = value ?? "";
  final regex = RegExp(r'^\d{6}$');
  if (!regex.hasMatch(inputValue)) return false;
  int month = int.parse(inputValue.substring(0, 2));
  int year = int.parse(inputValue.substring(2, 6));
  final now = DateTime.now();
  if (month < 1 || month > 12) return false;
  if (year < now.year || (year == now.year && month < now.month)) {
    return false;
  }
  return true;
}