dateFormatYYYYMMDD static method

bool dateFormatYYYYMMDD(
  1. String str
)

Validate string as a date.

The str parameter should be a string representing a date in the YYYY-MM-dd format.

Returns true if the str is valid, false otherwise.

Implementation

static bool dateFormatYYYYMMDD(String str) {
  String pattern = r'/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/';
  RegExp regExp = RegExp(pattern);
  return regExp.hasMatch(str);
}