isDateTime static method
Checks that checkValue can be turned into a datetime.
DateFormat will be used to attempt to parse checkValue. Using the format
provided by dateFormat. If checkValue can't be passed then errorMessage if provided,
or the default error if not. Otherwise null is returned
Implementation
static String? isDateTime(String? checkValue,
{String dateFormat = "dd/MM/yyyy",
bool parseLoose = false,
errorMessage}) {
DateFormat df = DateFormat(dateFormat);
var parseFn = parseLoose ? df.parseLoose : df.parse;
try {
if (checkValue == null) {
throw const FormatException();
}
parseFn(checkValue);
} on FormatException {
return errorMessage ?? "Field must be a valid date";
}
return null;
}