validPhoneWithCountryCodeBR method
Validates that the string is a valid Brazilian phone number including
the country code 55 (format 55xx9xxxxxxxx, 13 digits).
message is the error string shown when validation fails.
Returns this to allow method chaining.
Example:
final phone = Field<String>('phone')
.validPhoneWithCountryCodeBR(message: 'Telefone com DDI inválido');
Implementation
Field<String> validPhoneWithCountryCodeBR({String message = ''}) {
return addValidator(message, (val) {
if (val == null || val.isEmpty) return false;
final clean = val.replaceAll(_nonDigitRegex, '');
if (clean.length != 13) return true;
return !clean.startsWith('55') || clean[4] != '9';
});
}