Skip to content

Commit

Permalink
modify regex so it ensures start of string when validating vat number…
Browse files Browse the repository at this point in the history
…s. see #2
  • Loading branch information
dannyvankooten committed Nov 2, 2016
1 parent c5de749 commit e86dfa1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function validateFormat( $vatNumber ) {
return false;
}

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

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public function test_validateFormat() {
'SE12345678901',
'SI1234567',
'SK123456789',
'fooGB999999973', // valid VAT number but with string prefix
];

foreach( $invalid as $format ) {
self::assertFalse( $validator->validateFormat( $format ), "{$format} passed validation, but shouldn't." );
$isValid = $validator->validateFormat( $format );
self::assertFalse( $isValid, "{$format} passed validation, but shouldn't." );
}
}

Expand Down

0 comments on commit e86dfa1

Please sign in to comment.