time static method
FormFieldValidator that requires the field's value to be a valid time.
It supports various time formats, both 24-hour and 12-hour formats.
Valid 24-hour time formats:
HH:mm
: Hours and minutes, e.g.,23:59
HH:mm:ss
: Hours, minutes, and seconds, e.g.,23:59:59
HH:mm:ss.SSS
: Hours, minutes, seconds, and milliseconds, e.g.,23:59:59.999
Valid 12-hour time formats:
h:mm a
: Hours and minutes with AM/PM, e.g.,11:59 PM
h:mm:ss a
: Hours, minutes, and seconds with AM/PM, e.g.,11:59:59 PM
h:mm:ss.SSS a
: Hours, minutes, seconds, and milliseconds with AM/PM, e.g.,11:59:59.999 PM
Parameters:
errorText
(optional): The error message when the time is invalid.checkNullOrEmpty
Whether to check for null or empty values.
This regex matches time in 24-hour or 12-hour format.
- It allows hours and minutes, with optional AM/PM for 12-hour format.
- It supports leading zeros for single-digit hours.
Examples: 23:59, 11:59 PM
Implementation
static FormFieldValidator<String> time({
String? errorText,
bool checkNullOrEmpty = true,
}) => TimeValidator(
errorText: errorText,
checkNullOrEmpty: checkNullOrEmpty,
).validate;