Skip to content

Commit

Permalink
merge #25
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Jan 16, 2020
2 parents 97c9b67 + c3c8c1c commit 38dcd80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class Validator
'DK' => '(\d{2} ?){3}\d{2}',
'EE' => '\d{9}',
'EL' => '\d{9}',
'ES' => '[A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8}',
'ES' => '([A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8})',
'FI' => '\d{8}',
'FR' => '[A-Z\d]{2}\d{9}',
'GB' => '\d{9}|\d{12}|(GD|HA)\d{3}',
'GB' => '(\d{9}|\d{12}|(GD|HA)\d{3})',
'HR' => '\d{11}',
'HU' => '\d{8}',
'IE' => '[A-Z\d]{8}|[A-Z\d]{9}',
'IE' => '([A-Z\d]{8}|[A-Z\d]{9})',
'IT' => '\d{11}',
'LT' => '(\d{9}|\d{12})',
'LU' => '\d{8}',
Expand Down Expand Up @@ -106,8 +106,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
return false;
}

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

/**
Expand Down
18 changes: 15 additions & 3 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/**
* Class ValidatorTest
* @package DvK\Tests\Vat
*
* Todo: Tests for validate method
*/
class ValidatorTest extends TestCase
{
Expand Down Expand Up @@ -92,7 +90,21 @@ public function testValidateVatNumberFormat()
'SE12345678901',
'SI1234567',
'SK123456789',
'fooGB999999973', // valid VAT number but with string prefix

// 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',
'BE0123456789_invalid_suffix',
'MT12345678_invalid_suffix',
'LT123456789_invalid_suffix',
];

foreach ($invalid as $format) {
Expand Down

0 comments on commit 38dcd80

Please sign in to comment.