Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 0db34e5

Browse files
authored
Merge pull request #12 from Ilhasoft/fix/cpf-validation
Fix CPF validation
2 parents a86fc38 + e2209e2 commit 0db34e5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

library/src/main/java/br/com/ilhasoft/support/validation/rule/CpfTypeRule.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public CpfTypeRule(TextView view, String errorMessage) {
3232
@Override
3333
protected boolean isValid(TextView view) {
3434
final String rawCpf = view.getText().toString().trim().replaceAll("[^\\d]", "");
35-
return rawCpf.length() == 11
35+
return rawCpf.length() == 11 && !onBlackList(rawCpf)
3636
&& (cpfDv(rawCpf, 1) == Character.getNumericValue(rawCpf.charAt(9))
3737
&& cpfDv(rawCpf, 2) == Character.getNumericValue(rawCpf.charAt(10)));
3838
}
@@ -58,6 +58,17 @@ private int cpfSum(final String rawCPF, final int step) {
5858
return sum;
5959
}
6060

61+
// Reference: https://github.com/concretesolutions/canarinho/blob/master/canarinho/src/main/java/br/com/concretesolutions/canarinho/validator/ValidadorCPF.java
62+
private boolean onBlackList(String rawCpf) {
63+
boolean equal = true;
64+
for (int i = 1; i < 11 && equal; i++) {
65+
if (rawCpf.charAt(i) != rawCpf.charAt(0)) {
66+
equal = false;
67+
}
68+
}
69+
return equal || rawCpf.equals("12345678909");
70+
}
71+
6172
@Override
6273
protected void onValidationSucceeded(TextView view) {
6374
super.onValidationSucceeded(view);

0 commit comments

Comments
 (0)