Strips any international prefix (such as +, 00, 011) present in the number provided, normalizes
the resulting number, and indicates if an international prefix was present.
public maybeStripInternationalPrefixAndNormalize ( string &$number, string $possibleIddPrefix ) : integer | ||
$number | string | the non-normalized telephone number that we wish to strip any international dialing prefix from. |
$possibleIddPrefix | string | string the international direct dialing prefix from the region we think this number may be dialed in |
리턴 | integer | the corresponding CountryCodeSource if an international dialing prefix could be removed from the number, otherwise CountryCodeSource.FROM_DEFAULT_COUNTRY if the number did not seem to be in international format. |
public function testMaybeStripInternationalPrefix() { $internationalPrefix = "00[39]"; $numberToStrip = "0034567700-3898003"; // Note the dash is removed as part of the normalization. $strippedNumber = "45677003898003"; $this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix."); // Now the number no longer starts with an IDD prefix, so it should now report // FROM_DEFAULT_COUNTRY. $this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $numberToStrip = "00945677003898003"; $this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix."); // Test it works when the international prefix is broken up by spaces. $numberToStrip = "00 9 45677003898003"; $this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix."); // Now the number no longer starts with an IDD prefix, so it should now report // FROM_DEFAULT_COUNTRY. $this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); // Test the + symbol is also recognised and stripped. $numberToStrip = "+45677003898003"; $strippedNumber = "45677003898003"; $this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_PLUS_SIGN, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of the plus symbol."); // If the number afterwards is a zero, we should not strip this - no country calling code begins // with 0. $numberToStrip = "0090112-3123"; $strippedNumber = "00901123123"; $this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); $this->assertEquals($strippedNumber, $numberToStrip, "The number supplied had a 0 after the match so shouldn't be stripped."); // Here the 0 is separated by a space from the IDD. $numberToStrip = "009 0-112-3123"; $this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix)); }