cpfOrCnpj method
use to validate cpfOrCnpj fields
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) => Mask.validations.cpfOrCnpj(
value,
error: 'your message error', // optional field
),
),
------------ or ------------
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: Mask.validations.cpfOrCnpj,
),
Implementation
String? cpfOrCnpj(
String? value, {
String errorCPF = 'CPF inválido',
String errorCNPJ = 'CNPJ inválido',
}) {
String? response = cpf(value, error: errorCPF);
if (response != null) response = cnpj(value, error: errorCNPJ);
return response;
}