Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to chose behavior if country is not supported #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading