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 3381e6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for Symfony 7
- Remove support of PHP 7.4

### Fixed

- Prevent letters as number

## [3.9.3] - 2023-11-29

### Added
Expand Down
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 3381e6a

Please sign in to comment.