validateExpiration method

bool validateExpiration(
  1. String _month,
  2. String _year
)

Implementation

bool validateExpiration(String _month, String _year) {
  var month = int.tryParse(_month);
  var year = int.tryParse(_year);

  if (month == null || year == null) return false;

  if (0 == month) return false;

  if (month > 12 || 1 > month) return false;

  if (0 == year) return false;

  var today = DateTime.now();

  if (2 == _year.length) {
    year = int.tryParse("${today.year.toString().substring(0, 2)}$year");
  }

  if (year == null || year < today.year) return false;

  if (year == today.year) {
    if (month > 12 || month < today.month + 1) return false;
  } else if (year > today.year && (month > 12 || 1 > month)) return false;

  return true;
}