time static method

String? time(
  1. String? value, {
  2. String errorMsg = 'Enter a valid time (HH:mm)',
})

⏰ Time Validator (HH:mm)

Implementation

static String? time(
  String? value, {
  String errorMsg = 'Enter a valid time (HH:mm)',
}) {
  if (value == null || value.isEmpty) return 'Time is required';
  final regex = RegExp(r'^(?:[01]\d|2[0-3]):[0-5]\d$');
  return regex.hasMatch(value) ? null : errorMsg;
}