Skip to content

Commit

Permalink
Allow to chose behavior if country is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 22, 2023
1 parent 905499c commit e5b758c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ 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.
*
* @param string $vatNumber
* @param bool $skipIfUnsupported
*
* @return boolean
*/
public function validateVatNumberFormat(string $vatNumber): bool
public function validateVatNumberFormat(string $vatNumber, bool $skipIfUnsupported = false): bool
{
if ($vatNumber === '') {
return false;
Expand All @@ -105,7 +113,7 @@ public function validateVatNumberFormat(string $vatNumber): bool
$number = substr($vatNumber, 2);

if (! isset($this->patterns[$country])) {
return false;
return $skipIfUnsupported;
}

return preg_match('/^' . $this->patterns[$country] . '$/', $number) > 0;
Expand Down

0 comments on commit e5b758c

Please sign in to comment.