validateYear static method

String? validateYear(
  1. String? value
)

Ensures that the input year is valid and not > the current year

Implementation

static String? validateYear(String? value) {
  if (value == null) {
    return 'Value cannot be empty';
  }

  int? parsedYear = int.tryParse(value);
  if (parsedYear == null) {
    return 'Unable to parse year from value, make sure value is an integer';
  }

  if (parsedYear > DateTime.now().year) {
    return 'Invalid year. Year must be <= the current year.';
  }

  return null;
}