validate static method

bool validate(
  1. String cpf
)

Returns true if the given cpf is valid.

CPF's can only have 2 valid formats:

  • Unformatted 11 digits.
  • Formatted 14 digits.

Implementation

static bool validate(String cpf) {
  if (cpf.length > 14 || cpf.length < 11) {
    return false;
  }

  var unformattedCpf = strip(cpf);
  var validatedCpf = CpfGenerator.generate(unformattedCpf.toCpfValidation());

  if (unformattedCpf == validatedCpf) {
    return true;
  }

  return false;
}