expiryValid static method

bool expiryValid(
  1. String value, {
  2. DateTime? now,
})

MM/YY not in the past relative to now.

Implementation

static bool expiryValid(String value, {DateTime? now}) {
  final m = RegExp(r'^(\d{2})\s*/?\s*(\d{2})$').firstMatch(value.trim());
  if (m == null) return false;
  final month = int.parse(m.group(1)!), year = 2000 + int.parse(m.group(2)!);
  if (month < 1 || month > 12) return false;
  final t = now ?? DateTime.now();
  return year > t.year || (year == t.year && month >= t.month);
}