Skip to content

Commit 33b1817

Browse files
authored
Merge pull request #2 from andrergcosta/melhorar_metodo_validateCnpj
Alteração da função validateCnpj para impedir que o Cnpj 00.000.000/0…
2 parents 3d58c3b + 3a2a55f commit 33b1817

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/validator-docs/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ protected function validateCnpj($attribute, $value)
7474
{
7575
$c = preg_replace('/\D/', '', $value);
7676

77-
$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
78-
79-
if (strlen($c) != 14) {
77+
if (strlen($c) != 14 || preg_match("/^{$c[0]}{14}$/", $c)) {
8078
return false;
8179
}
8280

81+
$b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
82+
8383
for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]) ;
8484

8585
if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {

0 commit comments

Comments
 (0)