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

Commit e2209e2

Browse files
author
Daniel San
committed
Fix CPF validation
Signed-off-by: Daniel San <danielsan@ilhasoft.com.br>
1 parent 51e7cff commit e2209e2

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
@@ -16,7 +16,7 @@ public CpfTypeRule(TextView view, String errorMessage) {
1616
@Override
1717
protected boolean isValid(TextView view) {
1818
final String rawCpf = view.getText().toString().trim().replaceAll("[^\\d]", "");
19-
return rawCpf.length() == 11
19+
return rawCpf.length() == 11 && !onBlackList(rawCpf)
2020
&& (cpfDv(rawCpf, 1) == Character.getNumericValue(rawCpf.charAt(9))
2121
&& cpfDv(rawCpf, 2) == Character.getNumericValue(rawCpf.charAt(10)));
2222
}
@@ -42,6 +42,17 @@ private int cpfSum(final String rawCPF, final int step) {
4242
return sum;
4343
}
4444

45+
// Reference: https://github.com/concretesolutions/canarinho/blob/master/canarinho/src/main/java/br/com/concretesolutions/canarinho/validator/ValidadorCPF.java
46+
private boolean onBlackList(String rawCpf) {
47+
boolean equal = true;
48+
for (int i = 1; i < 11 && equal; i++) {
49+
if (rawCpf.charAt(i) != rawCpf.charAt(0)) {
50+
equal = false;
51+
}
52+
}
53+
return equal || rawCpf.equals("12345678909");
54+
}
55+
4556
@Override
4657
protected void onValidationSucceeded(TextView view) {
4758
super.onValidationSucceeded(view);

0 commit comments

Comments
 (0)