You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/src/form_builder_validators.dart
+28-3Lines changed: 28 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -504,9 +504,34 @@ class FormBuilderValidators {
504
504
:null;
505
505
506
506
/// [FormFieldValidator] that requires the field's value to be a valid time string.
507
-
/// * [errorText] is the error message to display when the time is invalid
508
-
/// Valid time formats are `HH:mm:ss`, `HH:mm` and `HH:mm:ss.SSS` (24-hour clock)
509
-
/// and `h:mm:ss a`, `h:mm a` and `h:mm:ss.SSS a` (12-hour clock)
507
+
///
508
+
/// The validator supports various time formats, both 24-hour and 12-hour clocks.
509
+
///
510
+
/// ## Valid 24-hour time formats:
511
+
/// - `HH:mm`: Hours and minutes, e.g., `23:59`
512
+
/// - `HH:mm:ss`: Hours, minutes, and seconds, e.g., `23:59:59`
513
+
/// - `HH:mm:ss.SSS`: Hours, minutes, seconds, and milliseconds, e.g., `23:59:59.999`
514
+
///
515
+
/// ## Valid 12-hour time formats:
516
+
/// - `h:mm a`: Hours and minutes with AM/PM, e.g., `11:59 PM`
517
+
/// - `h:mm:ss a`: Hours, minutes, and seconds with AM/PM, e.g., `11:59:59 PM`
518
+
/// - `h:mm:ss.SSS a`: Hours, minutes, seconds, and milliseconds with AM/PM, e.g., `11:59:59.999 PM`
519
+
///
520
+
/// ## Parameters:
521
+
/// - [errorText] (optional): The error message to display when the time is invalid.
522
+
///
523
+
/// ## Returns:
524
+
/// A validator that checks if the field's value is a valid time string. If the value is null, empty, or not a valid time, it returns the [errorText] or a default error message.
525
+
///
526
+
/// Example usage:
527
+
/// ```dart
528
+
/// FormBuilderTextField(
529
+
/// name: 'time',
530
+
/// validator: FormBuilderValidators.time(errorText: 'Invalid time format'),
531
+
/// )
532
+
/// ```
533
+
///
534
+
/// If the [errorText] parameter is not provided, a default error message is used.
0 commit comments