Skip to content

Commit

Permalink
Formatter: Add support for starting zero like 0123...
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed May 20, 2021
1 parent 7b81a04 commit 28f5253
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/PhoneNumberFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class PhoneNumberFormatter
public static function fix(string $phone, int $region = 420): string
{
$phone = (string) preg_replace('/[^\d+]/', '', $phone); // remove spaces
$phone = (string) preg_replace('/^0([1-9])/', '$1', $phone); // remove starting zero
if (preg_match('/^(?:0{2,}|\+)\s*([1-9]\d{2})\s*(.+)$/', $phone, $phoneRegionParser)) {
$region = (int) ($phoneRegionParser[1] ?? throw new \LogicException('Invalid phone prefix.'));
$phone = '+' . $region . ($phoneRegionParser[2] ?? '');
Expand Down

0 comments on commit 28f5253

Please # to comment.