Skip to content

Commit c3c8c1c

Browse files
wrap all regexes with pipe-character in capturing group to properly capture start and end of string & disallow prefixes and suffixes. thank you @Swop!
1 parent 1c5775c commit c3c8c1c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Validator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class Validator
2222
'DK' => '(\d{2} ?){3}\d{2}',
2323
'EE' => '\d{9}',
2424
'EL' => '\d{9}',
25-
'ES' => '(?:[A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8})',
25+
'ES' => '([A-Z]\d{7}[A-Z]|\d{8}[A-Z]|[A-Z]\d{8})',
2626
'FI' => '\d{8}',
2727
'FR' => '[A-Z\d]{2}\d{9}',
28-
'GB' => '\d{9}|\d{12}|(GD|HA)\d{3}',
28+
'GB' => '(\d{9}|\d{12}|(GD|HA)\d{3})',
2929
'HR' => '\d{11}',
3030
'HU' => '\d{8}',
31-
'IE' => '[A-Z\d]{8}|[A-Z\d]{9}',
31+
'IE' => '([A-Z\d]{8}|[A-Z\d]{9})',
3232
'IT' => '\d{11}',
3333
'LT' => '(\d{9}|\d{12})',
3434
'LU' => '\d{8}',
@@ -106,8 +106,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
106106
return false;
107107
}
108108

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

113112
/**

0 commit comments

Comments
 (0)