Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Included test for repeated cpf digits

  • Loading branch information...
commit e0f26d4ec6ea6495f860a2198ad34648a59579ae 1 parent 77aac18
@CauanCabral CauanCabral authored
Showing with 11 additions and 4 deletions.
  1. +8 −4 Lib/BrValidation.php
  2. +3 −0  Test/Case/Lib/BrValidationTest.php
View
12 Lib/BrValidation.php
@@ -70,13 +70,17 @@ public static function cpf($check) {
return false;
}
- if (!ctype_digit($check)) {
- return false;
- }
-
if (strlen($check) != 11) {
return false;
}
+
+ // repeated values are invalid, but algorithms fails to check it
+ for($i = 0; $i < 10; $i++) {
+ if(str_repeat($i, 11) === $check) {
+ return false;
+ }
+ }
+
$dv = substr($check, -2);
for ($pos = 9; $pos <= 10; $pos++) {
$sum = 0;
View
3  Test/Case/Lib/BrValidationTest.php
@@ -78,6 +78,7 @@ public function testSsn() {
$this->assertFalse(BrValidation::cpf('50549727322'));
$this->assertFalse(BrValidation::cpf('869.283.422-11'));
$this->assertFalse(BrValidation::cpf('843.701.734-22'));
+ $this->assertFalse(BrValidation::cpf('999.999.999-99'));
$this->assertTrue(BrValidation::cpf('22692173813'));
$this->assertTrue(BrValidation::cpf('50549727302'));
@@ -121,5 +122,7 @@ public function testSsn() {
$this->assertFalse(BrValidation::ssn('33aaaa86000129'));
$this->assertFalse(BrValidation::ssn('22692173813xxx'));
$this->assertFalse(BrValidation::ssn('226921xxx73813'));
+ $this->assertFalse(BrValidation::ssn('11111111111'));
+ $this->assertFalse(BrValidation::cpf('abcdefghi'));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.