isValidDate static method

  1. @visibleForTesting
bool isValidDate(
  1. String yymmdd
)

Validates the date part (YYMMDD) of a South African ID number.

Returns true if the date is valid; otherwise, returns false.

Implementation

@visibleForTesting
static bool isValidDate(String yymmdd) {
  final year = int.parse(yymmdd.substring(0, 2));
  final month = int.parse(yymmdd.substring(2, 4));
  final day = int.parse(yymmdd.substring(4, 6));

  if (year < 0 || month < 1 || month > 12 || day < 1 || day > 31) {
    return false;
  }

  return true;
}