Skip to content

Commit

Permalink
Merge pull request #38 from gregorwagner/intl
Browse files Browse the repository at this point in the history
Bug 1136211: Handle global region.
  • Loading branch information
andreasgal committed Mar 5, 2015
2 parents 2bb48a8 + 4c0b8b5 commit 1841132
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions PhoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ var PhoneNumber = (function (dataBase) {
// Remove formating characters and whitespace.
number = PhoneNumberNormalizer.Normalize(number);

// If there is no defaultRegion, we can't parse international access codes.
if (!defaultRegion && number[0] !== '+')
// We can't parse international access codes f there is no defaultRegion
// or the defaultRegion is the global region.
if ((!defaultRegion || defaultRegion === '001') && number[0] !== '+')
return null;

// Detect and strip leading '+'.
Expand Down
14 changes: 7 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ CantParse("911", "US");
// China mobile number with a 0 in it
Format("15955042864", "CN", "15955042864", "CN", "0159 5504 2864", "+86 159 5504 2864");

// Formate international 001 numbers without country code.
Format("883510000000094", "001", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
Format("+883510000000094", "001", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
Format("883510000000094", "FR", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
// Testing international region numbers.
CantParse("883510000000091", "001");
Format("+883510000000092", "001", "510000000092", "001", "510 000 000 092", "+883 510 000 000 092");
Format("883510000000093", "FR", "510000000093", "001", "510 000 000 093", "+883 510 000 000 093");
Format("+883510000000094", "FR", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
Format("883510000000094", "US", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
Format("+883510000000094", "US", "510000000094", "001", "510 000 000 094", "+883 510 000 000 094");
Format("979510000012", "001", "510000012", "001", "5 1000 0012", "+979 5 1000 0012");
Format("883510000000095", "US", "510000000095", "001", "510 000 000 095", "+883 510 000 000 095");
Format("+883510000000096", "US", "510000000096", "001", "510 000 000 096", "+883 510 000 000 096");
CantParse("979510000012", "001");
Format("+979510000012", "001", "510000012", "001", "5 1000 0012", "+979 5 1000 0012");

// Test normalizing numbers. Only 0-9,#* are valid in a phone number.
Expand Down

0 comments on commit 1841132

Please sign in to comment.