Skip to content

Commit

Permalink
Merge pull request #29 from Talentify/bug/validate-postalcode
Browse files Browse the repository at this point in the history
Validate PostalCode has only numbers
  • Loading branch information
vivianequinaia authored May 3, 2021
2 parents 8536997 + d3e3999 commit 666fcfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Geography/Address/ByCountry/Us/ZipCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setValue(string $value): void
$characters++;
}

if (empty($value) || $characters != 5 && $characters != 9) {
if (empty($value) || ctype_digit($changedValue) !== true || ($characters != 5 && $characters != 9)) {
throw new \InvalidArgumentException(sprintf('The value "%s" is not a valid postal code.', $value));
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Geography/Address/ByCountry/Us/ZipCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public function invalidValueDataProvider() : array
return [
['', 'The value "" is not a valid postal code.'],
["\t\r\n", "The value \"\t\r\n\" is not a valid postal code."],
['235-895', 'The value "235895" is not a valid postal code.']
['235-895', 'The value "235895" is not a valid postal code.'],
['2A5-8E5', 'The value "2A5-8E5" is not a valid postal code.'],
['TEST', 'The value "TEST" is not a valid postal code.'],
['test', 'The value "test" is not a valid postal code.'],
];
}
}

0 comments on commit 666fcfb

Please sign in to comment.