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 **/