Skip to content

Commit

Permalink
Fix Phone field allowing invalid phone numbers and country codes
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jul 4, 2024
1 parent 57ebc70 commit 596a1b3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/models/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public function __toString()

return $phoneUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL);
} catch (NumberParseException $e) {
if ($this->number) {
$countryString = $this->country ? '(' . $this->country . ') ' : '';
if ($this->number && is_numeric($this->number)) {
// Consider the number still valid
$countryString = $this->country && is_numeric($this->country) ? '(' . $this->country . ') ' : '';

return $countryString . $this->number;
}
Expand Down Expand Up @@ -105,7 +106,11 @@ public function getCountryCode(): string
public function getCountryName(): string
{
if ($this->country) {
return Craft::$app->getAddresses()->getCountryRepository()->get($this->country)->getName();
try {
return Craft::$app->getAddresses()->getCountryRepository()->get($this->country)->getName();
} catch (Throwable $e) {

}
}

return '';
Expand Down

0 comments on commit 596a1b3

Please sign in to comment.