validateExpireDate static method
Валидация даты карты
Implementation
static bool validateExpireDate(String expiryDate) {
if (expiryDate.isEmpty || expiryDate.length != CardSettings.maxDateLength) {
return false;
}
int? month;
int? year;
month = int.tryParse(expiryDate.substring(0, 2));
year = int.tryParse(expiryDate.substring(2, 4));
if (month == null || year == null) {
return false;
}
if (month >= 1 && month <= 12) {
final DateTime currentDateTime = DateTime.now();
final int currentMonth = currentDateTime.month;
final String currentYearStr =
currentDateTime.year.toString().substring(2);
final int currentYear = int.parse(currentYearStr);
if (year == currentYear && month >= currentMonth) {
return true;
}
if (year > currentYear && year <= currentYear + 20) {
return true;
}
}
return false;
}