From 0e152cda6797a83e4d2bb92f05f0f0813b6c0c80 Mon Sep 17 00:00:00 2001 From: Daniel Rodrigues Date: Wed, 16 Sep 2026 19:17:22 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20valida=C3=A7=C3=A3o=20de=20DDD=20para?= =?UTF-8?q?=20exigir=20exatamente=202=20d=C3=ADgitos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator-docs/Rules/Ddd.php | 4 ++-- tests/TestValidator.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/validator-docs/Rules/Ddd.php b/src/validator-docs/Rules/Ddd.php index b4589d5..aeffd5e 100644 --- a/src/validator-docs/Rules/Ddd.php +++ b/src/validator-docs/Rules/Ddd.php @@ -8,7 +8,7 @@ final class Ddd { public function validateDdd($attribute, $ddd): bool { - if (preg_match('/([1-9]{2}+)/', $ddd, $matches) <= 0) { + if (preg_match('/^[1-9]{2}$/', (string) $ddd, $matches) <= 0) { return false; } @@ -30,6 +30,6 @@ public function validateDdd($attribute, $ddd): bool range(91, 99) ); - return in_array($dddExtracted, $dddExisting); + return in_array($dddExtracted, $dddExisting, true); } } diff --git a/tests/TestValidator.php b/tests/TestValidator.php index 2a870b4..17fbd18 100644 --- a/tests/TestValidator.php +++ b/tests/TestValidator.php @@ -337,9 +337,21 @@ public function ddd() ['errado' => 'ddd'] ); + $incorrectWithThreeDigits = Validator::make( + ['errado' => '011'], + ['errado' => 'ddd'] + ); + + $incorrectWithAlphaNumeric = Validator::make( + ['errado' => '11a'], + ['errado' => 'ddd'] + ); + $this->assertTrue($correct->passes()); $this->assertTrue($incorrect->fails()); + $this->assertTrue($incorrectWithThreeDigits->fails()); + $this->assertTrue($incorrectWithAlphaNumeric->fails()); } /** @test **/