isValid static method

bool isValid(
  1. String? cnpj, {
  2. dynamic stripBeforeValidation = true,
})

Implementation

static bool isValid(String? cnpj, {stripBeforeValidation = true}) {
  if (stripBeforeValidation) {
    cnpj = strip(cnpj);
  }

  // cnpj must be defined
  if (cnpj == null || cnpj.isEmpty) {
    return false;
  }

  // cnpj must have 14 chars
  if (cnpj.length != 14) {
    return false;
  }

  // cnpj can't be blacklisted
  if (blockList.contains(cnpj)) {
    return false;
  }

  var numbers = cnpj.substring(0, 12);
  numbers += _verifierDigit(numbers).toString();
  numbers += _verifierDigit(numbers).toString();

  return numbers.substring(numbers.length - 2) ==
      cnpj.substring(cnpj.length - 2);
}