validate method
Validates the provided value
.
Returns null
if the value is valid; otherwise, returns a validation error message.
Implementation
@override
String? validate(covariant String value) {
String cep = mode.isUnformatted ? value.onlyDigits : value;
final regex =
mode.isFormatted ? RegExp(r'^\d{5}-\d{3}$') : RegExp(r'^\d{8}$');
if (!regex.hasMatch(cep)) return message;
if (cep.onlyDigits.isRepeatedCharacters) return message;
return null;
}