validator method
A function that must return a validation error if the provided
value is invalid and null otherwise.
Implementation
@override
PhoneNumberError? validator(String value) {
final trimmed = value.trim();
if (trimmed.isEmpty) return PhoneNumberError.empty;
if (trimmed.length < minLength) return PhoneNumberError.tooShort;
if (maxLength != null && trimmed.length > maxLength!) {
return PhoneNumberError.tooLong;
}
return null;
}