# isCpf property

bool get isCpf

Checks if the cpf is valid.

## Implementation

    bool get isCpf {
      // get only the numbers
      String numbers = replaceAll(RegExp(r'[^0-9]'), '');
      // Test if the CPF has 11 digits
      if (numbers.length != 11) {
        return false;
      }

      // Test if all CPF digits are the same
      if (RegExp(r'^(\d)\1*$').hasMatch(numbers)) {
        return false;
      }

      // split the digits
      List<int> digits = numbers.split('').map(int.parse).toList();

      // Calculate the first verifier digit
      int calcDv1 = 0;
      for (int i in Iterable<int>.generate(9, (int i) => 10 - i)) {
        calcDv1 += digits[10 - i] * i;
      }
      calcDv1 %= 11;

      int dv1 = calcDv1 < 2 ? 0 : 11 - calcDv1;

      // Tests the first verifier digit
      if (digits[9] != dv1) {
        return false;
      }

      // Calculate the second verifier digit
      int calcDv2 = 0;
      for (int i in Iterable<int>.generate(10, (int i) => 11 - i)) {
        calcDv2 += digits[11 - i] * i;
      }
      calcDv2 %= 11;

      int dv2 = calcDv2 < 2 ? 0 : 11 - calcDv2;

      // Test the second verifier digit
      if (digits[10] != dv2) {
        return false;
      }

      return true;
    }