validator static method
A TextFormField.validator that returns the first unmet rule's title,
so Form.validate() checks the same rules as the checklist. Empty is
"Required", or fine when optional.
Implementation
static String? Function(String?) validator(
List<RegexModel> rules, {
bool optional = false,
}) => (value) {
if ((value ?? '').isEmpty) {
return optional ? null : RegexLabels.current.required;
}
for (final rule in rules) {
if (!rule.matches(value!)) return rule.title;
}
return null;
};