diff --git a/src/Validator.php b/src/Validator.php index fc3e199..12e7770 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -87,6 +87,13 @@ public function validateIpAddress(string $ipAddress): bool return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE); } + public function hasSupportedCountryPrefix(string $vatNumber): bool + { + $country = substr($vatNumber, 0, 2); + + return isset($this->patterns[$country]); + } + /** * Validate a VAT number format. This does not check whether the VAT number was really issued. * @@ -105,7 +112,7 @@ public function validateVatNumberFormat(string $vatNumber): bool $number = substr($vatNumber, 2); if (! isset($this->patterns[$country])) { - return false; + throw new \InvalidArgumentException('The vat country prefix is not supported.'); } return preg_match('/^' . $this->patterns[$country] . '$/', $number) > 0; diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 847bc49..b4fb3f3 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -96,14 +96,6 @@ public function testValidateVatNumberFormat() 'SI1234567', 'SK123456789', - // valid number but with prefix - 'invalid_prefix_GB999999973', - 'invalid_prefix_IE1234567X', - 'invalid_prefix_ESB1234567C', - 'invalid_prefix_BE0123456789', - 'invalid_prefix_MT12345678', - 'invalid_prefix_LT123456789', - // valid number but with suffix 'IE1234567X_invalid_suffix', 'ESB1234567C_invalid_suffix',