diff --git a/src/DgiiRncValidator.php b/src/DgiiRncValidator.php index 4ad0c2b..40c30c8 100755 --- a/src/DgiiRncValidator.php +++ b/src/DgiiRncValidator.php @@ -16,6 +16,11 @@ class DgiiRncValidator public static function validateRNC(string $string): bool { $cleanedId = Utils::getNumbers($string); + + if (!$cleanedId) { + return false; + } + preg_match('/^(\d{9}|\d{11})$/', $cleanedId, $matches); return (bool) count($matches); diff --git a/tests/DgiiRncValidatorTest.php b/tests/DgiiRncValidatorTest.php index b12dd40..203fee6 100644 --- a/tests/DgiiRncValidatorTest.php +++ b/tests/DgiiRncValidatorTest.php @@ -28,3 +28,12 @@ ->and(DgiiRncValidator::check('123456789')) ->toBeFalse(); }); + +test('check if the given string without numbers is a valid RNC', function () { + $id = 'abc cdd'; + expect(DgiiRncValidator::validateRNC($id))->toBeFalse(); + $id = ' '; + expect(DgiiRncValidator::validateRNC($id))->toBeFalse(); + $id = ''; + expect(DgiiRncValidator::validateRNC($id))->toBeFalse(); +});