Skip to content

Commit

Permalink
wrap all regexes with pipe-character in capturing group to properly c…
Browse files Browse the repository at this point in the history
…apture start and end of string & disallow prefixes and suffixes. thank you @Swop!
  • Loading branch information
dannyvankooten committed Jan 16, 2020
1 parent 1c5775c commit c3c8c1c
Showing 1 changed file with 4 additions and 5 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

0 comments on commit c3c8c1c

Please sign in to comment.