Skip to content

Commit

Permalink
bug: Prevent letters as number
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias committed Nov 29, 2023
1 parent ba04e0f commit fd41a98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Form/DataTransformer/PhoneNumberToArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function reverseTransform($value): ?PhoneNumber

$util = PhoneNumberUtil::getInstance();

if (preg_match('/\p{L}/u', $value['number'])) {
throw new TransformationFailedException('The number can not contain letters.');
}

try {
$phoneNumber = $util->parse($value['number'], $value['country']);
} catch (NumberParseException $e) {
Expand Down
4 changes: 4 additions & 0 deletions src/Form/DataTransformer/PhoneNumberToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function reverseTransform($value): ?PhoneNumber
return null;
}

if (preg_match('/\p{L}/u', $value)) {
throw new TransformationFailedException('The number can not contain letters.');
}

try {
return PhoneNumberUtil::getInstance()->parse($value, $this->defaultRegion);
} catch (NumberParseException $e) {
Expand Down

0 comments on commit fd41a98

Please sign in to comment.