cpf method
use to validate cpf fields
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) => Mask.validations.cpf(
value,
error: 'your message error', // optional field
),
),
------------ or ------------
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: Mask.validations.cpf,
),
Implementation
String? cpf(String? value, {String error = 'CPF inválido'}) {
String numbers = CPFValidator.strip(value ?? "");
if (numbers.length != 11 || !CPFValidator.isValid(value ?? "")) {
return error;
}
return null;
}