Commits

Anonymous committed 88cc5c5

JAVA: libphonenumber v4.7. Mainly metadata updates.

  • Participants
  • Parent commits 5a32889
  • Branches default

Comments (0)

Files changed (51)

File java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

   static final int MAX_LENGTH_FOR_NSN = 16;
   // The maximum length of the country calling code.
   static final int MAX_LENGTH_COUNTRY_CODE = 3;
+  // We don't allow input strings for parsing to be longer than 250 chars. This prevents malicious
+  // input from overflowing the regular-expression engine.
+  private static final int MAX_INPUT_STRING_LENGTH = 250;
   static final String META_DATA_FILE_PREFIX =
       "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto";
   private String currentFilePrefix = META_DATA_FILE_PREFIX;
   // plus_sign*(([punctuation]|[star])*[digits]){3,}([punctuation]|[star]|[digits]|[alpha])*
   // Note VALID_PUNCTUATION starts with a -, so must be the first in the range.
   private static final String VALID_PHONE_NUMBER =
-      "[" + PLUS_CHARS + "]*(?:[" + VALID_PUNCTUATION + STAR_SIGN + "]*" + DIGITS + "){3,}[" +
+      "[" + PLUS_CHARS + "]*+(?:[" + VALID_PUNCTUATION + STAR_SIGN + "]*" + DIGITS + "){3,}[" +
       VALID_PUNCTUATION + STAR_SIGN + VALID_ALPHA + DIGITS + "]*";
 
   // Default extension prefix to use when formatting. This will be put in front of any extension
     } else {
       // Invalid region entered as country-calling-from (so no metadata was found for it) or the
       // region chosen has multiple international dialling prefixes.
+      LOGGER.log(Level.WARNING,
+                 "Trying to format number from invalid region "
+                 + regionCallingFrom
+                 + ". International formatting applied.");
       prefixNumberWithCountryCallingCode(countryCode,
-                           PhoneNumberFormat.INTERNATIONAL,
-                           formattedNumber);
+                                         PhoneNumberFormat.INTERNATIONAL,
+                                         formattedNumber);
     }
     return formattedNumber.toString();
   }
     if (numberToParse == null) {
       throw new NumberParseException(NumberParseException.ErrorType.NOT_A_NUMBER,
                                      "The phone number supplied was null.");
+    } else if (numberToParse.length() > MAX_INPUT_STRING_LENGTH) {
+      throw new NumberParseException(NumberParseException.ErrorType.TOO_LONG,
+                                     "The string supplied was too long to parse.");
     }
     // Extract a possible number from the string passed in (this strips leading characters that
     // could not be the start of a phone number.)

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AC

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BY

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ET

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GH

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KR

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KW

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KY

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LU

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MD

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NE

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NZ

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SA

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SC

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SL

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SN

Binary file modified.

File java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ

Binary file modified.

File java/libphonenumber/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java

 /**
  * Unit tests for AsYouTypeFormatter.java
  *
- * Note that these tests use the metadata contained in the files with TEST_META_DATA_FILE_PREFIX,
- * not the normal metadata files, so should not be used for regression test purposes - these tests
- * are illustrative only and test functionality.
+ * Note that these tests use the test metadata, not the normal metadata file, so should not be used
+ * for regression test purposes - these tests are illustrative only and test functionality.
  *
  * @author Shaopeng Jia
  */
-public class AsYouTypeFormatterTest extends TestCase {
-  private PhoneNumberUtil phoneUtil;
-
-  public AsYouTypeFormatterTest() {
-    phoneUtil = PhoneNumberUtilTest.initializePhoneUtilForTesting();
-  }
+public class AsYouTypeFormatterTest extends TestMetadataTestCase {
 
   public void testInvalidRegion() {
     AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter(RegionCode.ZZ);

File java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java

  * @author Tom Hofmann
  * @see PhoneNumberUtilTest {@link PhoneNumberUtilTest} for the origin of the test data
  */
-public class PhoneNumberMatcherTest extends TestCase {
-  private PhoneNumberUtil phoneUtil;
-
-  @Override
-  protected void setUp() throws Exception {
-    phoneUtil = PhoneNumberUtilTest.initializePhoneUtilForTesting();
-  }
+public class PhoneNumberMatcherTest extends TestMetadataTestCase {
 
   /** See {@link PhoneNumberUtilTest#testParseNationalNumber()}. */
   public void testFindNationalNumber() throws Exception {
     assertEquals(expected, actual);
   }
 
+  public void testNonPlusPrefixedNumbersNotFoundForInvalidRegion() throws Exception {
+    // Does not start with a "+", we won't match it.
+    Iterable<PhoneNumberMatch> iterable = phoneUtil.findNumbers("1 456 764 156", RegionCode.ZZ);
+    Iterator<PhoneNumberMatch> iterator = iterable.iterator();
+
+    assertFalse(iterator.hasNext());
+    try {
+      iterator.next();
+      fail("Violation of the Iterator contract.");
+    } catch (NoSuchElementException e) { /* Success */ }
+    assertFalse(iterator.hasNext());
+  }
+
   public void testEmptyIteration() throws Exception {
     Iterable<PhoneNumberMatch> iterable = phoneUtil.findNumbers("", RegionCode.ZZ);
     Iterator<PhoneNumberMatch> iterator = iterable.iterator();

File java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

 /**
  * Unit tests for PhoneNumberUtil.java
  *
- * Note that these tests use the metadata contained in the files with TEST_META_DATA_FILE_PREFIX,
- * not the normal metadata files, so should not be used for regression test purposes - these tests
- * are illustrative only and test functionality.
+ * Note that these tests use the test metadata, not the normal metadata file, so should not be used
+ * for regression test purposes - these tests are illustrative only and test functionality.
  *
  * @author Shaopeng Jia
  * @author Lara Rennie
  */
-public class PhoneNumberUtilTest extends TestCase {
-  private PhoneNumberUtil phoneUtil;
-  // This is used by BuildMetadataProtoFromXml.
-  static final String TEST_META_DATA_FILE_PREFIX =
-      "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
-
+public class PhoneNumberUtilTest extends TestMetadataTestCase {
   // Set up some test numbers to re-use.
   private static final PhoneNumber ALPHA_NUMERIC_NUMBER =
       new PhoneNumber().setCountryCode(1).setNationalNumber(80074935247L);
   private static final PhoneNumber INTERNATIONAL_TOLL_FREE_TOO_LONG =
       new PhoneNumber().setCountryCode(800).setNationalNumber(1234567890L);
 
-  public PhoneNumberUtilTest() {
-    phoneUtil = initializePhoneUtilForTesting();
-  }
-
-  static PhoneNumberUtil initializePhoneUtilForTesting() {
-    PhoneNumberUtil.resetInstance();
-    return PhoneNumberUtil.getInstance(
-        TEST_META_DATA_FILE_PREFIX,
-        CountryCodeToRegionCodeMapForTesting.getCountryCodeToRegionCodeMap());
-  }
-
   public void testGetSupportedRegions() {
     assertTrue(phoneUtil.getSupportedRegions().size() > 0);
   }
     // Invalid country calling codes.
     invalidNumber.setCountryCode(3923).setNationalNumber(2366L);
     assertFalse(phoneUtil.isValidNumberForRegion(invalidNumber, RegionCode.ZZ));
-    invalidNumber.setCountryCode(3923).setNationalNumber(2366L);
-    assertFalse(phoneUtil.isValidNumberForRegion(invalidNumber, RegionCode.UN001));
-    invalidNumber.setCountryCode(0).setNationalNumber(2366L);
     assertFalse(phoneUtil.isValidNumberForRegion(invalidNumber, RegionCode.UN001));
     invalidNumber.setCountryCode(0);
+    assertFalse(phoneUtil.isValidNumberForRegion(invalidNumber, RegionCode.UN001));
     assertFalse(phoneUtil.isValidNumberForRegion(invalidNumber, RegionCode.ZZ));
   }
 
     assertEquals(premiumNumber, phoneUtil.parse("0900 a332 600A5", RegionCode.NZ));
   }
 
+  public void testParseMaliciousInput() throws Exception {
+    // Lots of leading + signs before the possible number.
+    StringBuilder maliciousNumber = new StringBuilder(6000);
+    for (int i = 0; i < 6000; i++) {
+      maliciousNumber.append('+');
+    }
+    maliciousNumber.append("12222-33-244 extensioB 343+");
+    try {
+      phoneUtil.parse(maliciousNumber.toString(), RegionCode.US);
+      fail("This should not parse without throwing an exception " + maliciousNumber);
+    } catch (NumberParseException e) {
+      // Expected this exception.
+      assertEquals("Wrong error type stored in exception.",
+                   NumberParseException.ErrorType.TOO_LONG,
+                   e.getErrorType());
+    }
+    StringBuilder maliciousNumberWithAlmostExt = new StringBuilder(6000);
+    for (int i = 0; i < 350; i++) {
+      maliciousNumberWithAlmostExt.append("200");
+    }
+    maliciousNumberWithAlmostExt.append(" extensiOB 345");
+    try {
+      phoneUtil.parse(maliciousNumberWithAlmostExt.toString(), RegionCode.US);
+      fail("This should not parse without throwing an exception " + maliciousNumberWithAlmostExt);
+    } catch (NumberParseException e) {
+      // Expected this exception.
+      assertEquals("Wrong error type stored in exception.",
+                   NumberParseException.ErrorType.TOO_LONG,
+                   e.getErrorType());
+    }
+  }
+
   public void testParseWithInternationalPrefixes() throws Exception {
     assertEquals(US_NUMBER, phoneUtil.parse("+1 (650) 253-0000", RegionCode.NZ));
     assertEquals(INTERNATIONAL_TOLL_FREE, phoneUtil.parse("011 800 1234 5678", RegionCode.US));

File java/libphonenumber/test/com/google/i18n/phonenumbers/ShortNumberUtilTest.java

  *
  * @author Shaopeng Jia
  */
-public class ShortNumberUtilTest extends TestCase {
+public class ShortNumberUtilTest extends TestMetadataTestCase {
   private ShortNumberUtil shortUtil;
-  static final String TEST_META_DATA_FILE_PREFIX =
-      "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
 
   public ShortNumberUtilTest() {
-    PhoneNumberUtil.resetInstance();
-    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(
-        TEST_META_DATA_FILE_PREFIX,
-        CountryCodeToRegionCodeMapForTesting.getCountryCodeToRegionCodeMap());
     shortUtil = new ShortNumberUtil(phoneUtil);
   }
 

File java/libphonenumber/test/com/google/i18n/phonenumbers/TestMetadataTestCase.java

+/*
+ * Copyright (C) 2012 The Libphonenumber Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.i18n.phonenumbers;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Root class for PhoneNumberUtil tests that depend on the test metadata file.
+ * <p>
+ * Note since tests that extend this class do not use the normal metadata file, they should not be
+ * used for regression test purposes.
+ *
+ * @author Shaopeng Jia
+ * @author Lara Rennie
+ */
+public class TestMetadataTestCase extends TestCase {
+  private static final String TEST_META_DATA_FILE_PREFIX =
+      "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
+
+  protected final PhoneNumberUtil phoneUtil;
+
+  public TestMetadataTestCase() {
+    phoneUtil = initializePhoneUtilForTesting();
+  }
+
+  static PhoneNumberUtil initializePhoneUtilForTesting() {
+    PhoneNumberUtil.resetInstance();
+    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(
+        TEST_META_DATA_FILE_PREFIX,
+        CountryCodeToRegionCodeMapForTesting.getCountryCodeToRegionCodeMap());
+    return phoneUtil;
+  }
+}

File java/release_notes.txt

+March 16th, 2012: libphonenumber-4.7
+* Bug fixes
+ - Now return "too long" for input that is longer than 250 chars when parsing
+* Metadata changes
+ - AC,AM,AT,AZ,BF,BR,BY,BZ,CR,CU,DE,DJ,EE,EG,ET,GA,GH,HK,HN,ID,IN,JP,KE,KG,KH,KR,KW,KY,LB,LU,MA,MD,
+   MK,NA,NE,NZ,SA,SB,SC,SE,SL,SN,UZ
+ * Refactoring of test classes so that tests requiring the test metadata to be loaded have a common
+   base class which handles this.
+
 February 9th, 2012: libphonenumber-4.6
 * Bug fixes
  - Fix for formatByPattern to enable RFC formatting to work

File resources/PhoneNumberMetaData.xml

      applied.
 
      Country code, international and national prefix information main source:
-     http://www.itu.int/publ/T-SP-E.164C-2010/en
+     http://www.itu.int/pub/T-SP-E.164C-2011
 
      Emergency numbers Wikipedia source:
      http://en.wikipedia.org/wiki/Emergency_telephone_number
     <territory id="AC" countryCode="247" internationalPrefix="00">
       <!-- Formatted as a block. -->
       <generalDesc>
-        <nationalNumberPattern>[2-46]\d{3}</nationalNumberPattern>
+        <nationalNumberPattern>[2-467]\d{3}</nationalNumberPattern>
         <possibleNumberPattern>\d{4}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
+        <!-- The prefix 70 has been added since it has been seen online, such as for the number of
+             the Ascension Island local government itself. -->
         <nationalNumberPattern>
           (?:
             3[0-5]|
             4[4-6]|
-            [26]\d
+            [26]\d|
+            70
           )\d{2}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{4}</possibleNumberPattern>
                nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)">
       <availableFormats>
         <numberFormat pattern="(\d{2})(\d{6})">
-          <leadingDigits>1</leadingDigits>
+          <leadingDigits>
+            1|
+            47
+          </leadingDigits>
           <format>$1 $2</format>
         </numberFormat>
         <numberFormat pattern="(\d{2})(\d{6})" nationalPrefixFormattingRule="$NP$FG">
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[1-35-9]\d{7}</nationalNumberPattern>
+        <nationalNumberPattern>[1-9]\d{7}</nationalNumberPattern>
         <possibleNumberPattern>\d{5,8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
+        <!-- Includes telephone numbers in Nagorno-Karabakh Republic, physically located inside
+             Azerbaijan. -->
         <nationalNumberPattern>
           (?:
             10\d|
               6[1-9]|
               8[1-7]
             )|
-            3[12]2
+            3[12]2|
+            47\d
           )\d{5}
         </nationalNumberPattern>
         <exampleNumber>10123456</exampleNumber>
       </fixedLine>
       <mobile>
         <!-- Adding 55 from online numbers found and SMSs received from numbers with this prefix. It
-             seems to be used by Orange Armenia.  -->
+             seems to be used by Orange Armenia. Part of the range 97 is used by Nagorno-Karabakh
+             Republic. -->
         <nationalNumberPattern>
           (?:
             55|
           (?:
             2(?:
               1[467]|
-              2[134-8]|
+              2[13-8]|
               5[2357]|
               6[1-46-8]|
               7[1-8]|
           </leadingDigits>
           <format>$1 $2 $3 $4</format>
         </numberFormat>
-        <numberFormat pattern="(\d{2})(\d{2})(\d{2})(\d{2})">
-          <leadingDigits>22</leadingDigits>
-          <format>$1 $2 $3 $4</format>
-        </numberFormat>
-        <numberFormat pattern="(\d{2})(\d{2})(\d{2})(\d{2})">
-          <leadingDigits>36[0-46-9]</leadingDigits>
-          <format>$1 $2 $3 $4</format>
-        </numberFormat>
-        <numberFormat pattern="(\d{3})(\d)(\d{2})(\d{2})">
-          <leadingDigits>
-            1[013-79]|
-            2(?:
-              [45][13-9]|
-              [7-9]
-            )
-          </leadingDigits>
-          <format>$1 $2 $3 $4</format>
-        </numberFormat>
-        <numberFormat pattern="(\d{2})(\d{3})(\d{2})(\d{2})"
-          nationalPrefixFormattingRule="$NP$FG">
+        <numberFormat pattern="(\d{2})(\d{3})(\d{2})(\d{2})" nationalPrefixFormattingRule="$NP$FG">
           <leadingDigits>[4-8]</leadingDigits>
           <format>$1 $2 $3 $4</format>
         </numberFormat>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[1-9]\d{7,8}</nationalNumberPattern>
-        <possibleNumberPattern>\d{5,9}</possibleNumberPattern>
-      </generalDesc>
-      <fixedLine>
-        <!-- Added the 164 area code after it was found in other online lists and in many online
-             numbers. Also includes the area code 44 for CDMA regions, which are classified under
-             "Fixed Network" by the national plan.
-             The following regexp covers both the pre and post August 1st 2011 plans running in
-             parallel until December 31st 2011. -->
-        <nationalNumberPattern>
-          (?:
-            1(?:
-              (?:
-                [28]\d|
-                9
-              )\d|
+        <nationalNumberPattern>[1-9]\d{8}</nationalNumberPattern>
+        <possibleNumberPattern>\d{7,9}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <nationalNumberPattern>
+          (?:
+            1[28]\d|
+            2(?:
               02|
-              1[0-589]|
-              3[358]|
-              4[013-79]|
-              5[0-479]|
-              6[02346-9]|
-              7[0-24-8]
-            )|
-            2(?:
-              02\d|
-              1(?:
-                2[0-8]|
-                42|
-                6
-              )|
-              2(?:
-                2[0-79]|
-                3[0-35]|
-                42|
-                [1-35-9]|
-              )|
-              3(?:
-                3[0-58]|
-                [0-24]
-              )|
-              4(?:
-                2[0124579]|
-                [1468]
-              )|
-              5(?:
-                2[0124579]|
-                5
-              )|
-              6(?:
-                2\d|
-                3[0128]|
-                [56]
-              )|
-              79
-            )|
-            365?\d|
-            44\d{2}
-          )\d{5}
+              1[24]|
+              2[2-4]|
+              33|
+              [45]2|
+              6[23]
+            )|
+            365
+          )\d{6}
         </nationalNumberPattern>
         <exampleNumber>123123456</exampleNumber>
       </fixedLine>
       <mobile>
         <nationalNumberPattern>
           (?:
-            [46]0|
+            4[04]|
             5[015]|
+            60|
             7[07]
           )\d{7}
         </nationalNumberPattern>
              Including 716 as well since many numbers seem to have this prefix. -->
         <nationalNumberPattern>
           (?:
-            60[0-3]|
+            6(?:
+              0[0-3]|
+              8\d
+            )|
             7(?:
               [02-68]\d|
               1[0-4689]|
-              7[0-6]|
+              7[0-69]|
               9[0-689]
             )
           )\d{5}
     </territory>
 
     <!-- Brazil -->
-    <!-- http://en.wikipedia.org/wiki/%2B55 -->
+    <!-- http://en.wikipedia.org/wiki/%2B55
+         http://www.itu.int/oth/T020200001D/en -->
     <territory id="BR" countryCode="55"
                internationalPrefix="00(?:1[45]|2[135]|[34]1|43)"
                nationalPrefix="0"
-               nationalPrefixForParsing="0(?:(1[245]|2[135]|[34]1)(\d{10}))?"
+               nationalPrefixForParsing="0(?:(1[245]|2[135]|[34]1)(\d{10,11}))?"
                nationalPrefixTransformRule="$2">
       <!--The national prefix for parsing here also contains a capturing group for the main number,
            since the carrier codes here may also be area codes, so we want to check the length of
            number without the carrier code. -->
       <availableFormats>
         <numberFormat nationalPrefixFormattingRule="($FG)"
+          pattern="(\d{2})(\d{5})(\d{4})"
+          carrierCodeFormattingRule="$NP $CC ($FG)">
+          <leadingDigits>119</leadingDigits>
+          <format>$1 $2-$3</format>
+        </numberFormat>
+        <numberFormat nationalPrefixFormattingRule="($FG)"
           pattern="(\d{2})(\d{4})(\d{4})"
           carrierCodeFormattingRule="$NP $CC ($FG)">
           <leadingDigits>[1-9][1-9]</leadingDigits>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[1-9]\d{7,9}</nationalNumberPattern>
-        <possibleNumberPattern>\d{8,10}</possibleNumberPattern>
+        <nationalNumberPattern>
+          [1-46-9]\d{7,10}|
+          5\d{8,9}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{8,11}</possibleNumberPattern>
       </generalDesc>
       <noInternationalDialling>
         <nationalNumberPattern>[34]00\d{5}</nationalNumberPattern>
         <nationalNumberPattern>
           1(?:
             1(?:
-              [6-9]\d|
-              5[347]
+              5[347]|
+              [6-8]\d|
+              9\d{1,2}
             )|
             [2-9][6-9]\d
           )\d{6}|
             7[13-579]
           )[6-9]\d{7}
         </nationalNumberPattern>
-        <possibleNumberPattern>\d{10}</possibleNumberPattern>
+        <possibleNumberPattern>\d{10,11}</possibleNumberPattern>
         <exampleNumber>1161234567</exampleNumber>
       </mobile>
       <tollFree>
       </availableFormats>
       <generalDesc>
         <nationalNumberPattern>
-          [12-4]\d{8}|
+          [1-4]\d{8}|
           [89]\d{9,10}
         </nationalNumberPattern>
         <!-- Numbers are often written without the city code. -->
         <exampleNumber>2221234</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- 62[6-9] and 63X were added as we have been able to successfully send SMSs to these
-             numbers. -->
-        <nationalNumberPattern>
-          6(?:
-            [0-3]\d|
-            [67][01]
-          )\d{4}
-        </nationalNumberPattern>
+        <!-- 62[6-9], 63X and 6[67][2-9] were added as we have been able to successfully send SMSs
+             to these numbers or many numbers have been found online. -->
+        <nationalNumberPattern>6[0-367]\d{5}</nationalNumberPattern>
         <possibleNumberPattern>\d{7}</possibleNumberPattern>
         <exampleNumber>6221234</exampleNumber>
       </mobile>
     <!-- Costa Rica -->
     <!-- http://www.itu.int/oth/T0202000030/en -->
     <territory id="CR" countryCode="506" internationalPrefix="00"
-      nationalPrefixForParsing="(19(?:0[0-2]|19|77))" carrierCodeFormattingRule="$CC $FG">
+      nationalPrefixForParsing="(19(?:0[0-2468]|19|66|77))" carrierCodeFormattingRule="$CC $FG">
       <availableFormats>
         <numberFormat pattern="(\d{4})(\d{4})">
           <leadingDigits>
         <exampleNumber>9001234567</exampleNumber>
       </premiumRate>
       <voip>
-        <nationalNumberPattern>
+        <!-- Including trunking service numbers starting with 5100. -->
+        <nationalNumberPattern>
+          210[0-6]\d{4}|
           40(?:
-            00\d{4}|
+            [04]0\d{4}|
             10[0-3]\d{3}|
             2(?:
               00\d|
               900
             )\d{2}|
             3[01]\d{4}|
-            5\d{5}
-          )
+            5\d{5}|
+            70[01]\d{3}
+          )|
+          5100\d{4}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
         <exampleNumber>40001234</exampleNumber>
           1(?:
             0(?:
               00|
+              15|
               2[2-4679]
             )|
             1(?:
               1[0-35-9]|
               37|
-              46|
+              [46]6|
               75|
               8[79]|
               9[0-379]
             )|
             2(?:
-              12|
-              22|
-              34
+              00|
+              [12]2|
+              34|
+              55
             )|
             333|
             400|
-            55[15]|
+            5(?:
+              15|
+              5[15]|
+            )
             693|
             7(?:
               00|
-              1[78]|
-              22|
+              1[789]|
+              2[02]|
               [67]7
             )
           )
           2[1-4]\d{5,6}|
           3(?:
             1\d{6}|
-            [23]\d{4,6})|
+            [23]\d{4,6}
+          )|
           4(?:
             [125]\d{5,6}|
             [36]\d{6}|
-            [78]\d{4,6})|
+            [78]\d{4,6}
+          )|
           7\d{6,7}
         </nationalNumberPattern>
         <exampleNumber>71234567</exampleNumber>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
         <exampleNumber>51234567</exampleNumber>
       </mobile>
-      <emergency>
-        <!-- http://www.cubaweb.cu/en/comunicaciones -->
-        <nationalNumberPattern>10[56]</nationalNumberPattern>
+      <shortCode>
+        <nationalNumberPattern>
+          1(?:
+            1(?:
+              6111|
+              8
+            )|
+            40
+          )
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{3,6}</possibleNumberPattern>
+        <exampleNumber>140</exampleNumber>
+      </shortCode>
+      <emergency>
+        <nationalNumberPattern>10[456]</nationalNumberPattern>
         <possibleNumberPattern>\d{3}</possibleNumberPattern>
         <exampleNumber>106</exampleNumber>
       </emergency>
         <exampleNumber>22345678</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- Includes paging numbers. -->
+        <!-- Includes paging numbers (they are mixed into the same block). -->
         <nationalNumberPattern>9[5-79]\d{6}</nationalNumberPattern>
         <exampleNumber>96123456</exampleNumber>
       </mobile>
           </leadingDigits>
           <format>$1 $2 $3</format>
         </numberFormat>
+        <numberFormat pattern="(1\d{2})(\d{5,11})">
+          <leadingDigits>181</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <!-- Where we have seen prefixes in use for the IVPN/User Group numbers, we format it the
+             way it is generally written. For other prefixes, we fall back to using a three-digit
+             prefix since we have currently no more information to allow us to format these more
+             precisely. -->
+        <numberFormat pattern="(18\d{3})(\d{6})">
+          <leadingDigits>18500</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="(18\d{2})(\d{7})">
+          <leadingDigits>18[68]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+        <numberFormat pattern="(18\d)(\d{8})">
+          <leadingDigits>18[2-579]</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
         <numberFormat pattern="(700)(\d{4})(\d{4})">
           <leadingDigits>700</leadingDigits>
           <format>$1 $2 $3</format>
         <possibleNumberPattern>\d{11}</possibleNumberPattern>
         <exampleNumber>70012345678</exampleNumber>
       </personalNumber>
+      <uan>
+        <!-- Using UAN for numbers marked in the plan as being assigned to International Virtual
+             Private Networks (0181) & User Groups (018[2-9]). These seem in practice to be assigned
+             to companies. More information here: http://de.wikipedia.org/wiki/Vorwahl_01 -->
+        <nationalNumberPattern>
+          18(?:
+            1\d{5,11}|
+            [2-9]\d{8}
+          )
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{8,14}</possibleNumberPattern>
+        <exampleNumber>18500123456</exampleNumber>
+      </uan>
       <emergency>
         <nationalNumberPattern>11[02]</nationalNumberPattern>
         <possibleNumberPattern>\d{3}</possibleNumberPattern>
     <!-- http://www.itu.int/oth/T020200003A/en -->
     <territory id="DJ" countryCode="253" internationalPrefix="00">
       <availableFormats>
-        <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
-          <format>$1 $2 $3</format>
-        </numberFormat>
         <numberFormat pattern="(\d{2})(\d{2})(\d{2})(\d{2})">
           <format>$1 $2 $3 $4</format>
         </numberFormat>
       </availableFormats>
-      <!--TODO: Remove support for 6-digit numbers after March 1st, 2012, when the national
-          numbering plan is going to migrate to 8 digits. -->
-      <generalDesc>
-        <nationalNumberPattern>[1-8]\d{5,7}</nationalNumberPattern>
-        <possibleNumberPattern>\d{6,8}</possibleNumberPattern>
+      <generalDesc>
+        <nationalNumberPattern>[27]\d{7}</nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
         <!-- Includes "Numéro long CDMA fixe" numbers. -->
         <nationalNumberPattern>
-          (?:
-            1[05]|
-            [2-5]\d
-          )\d{4}|
           2(?:
             1[2-5]|
             7[45]|
         <exampleNumber>21360003</exampleNumber>
       </fixedLine>
       <mobile>
-        <nationalNumberPattern>(?:77)?[6-8]\d{5}</nationalNumberPattern>
+        <nationalNumberPattern>77[6-8]\d{5}</nationalNumberPattern>
         <exampleNumber>77831001</exampleNumber>
       </mobile>
       <emergency>
     <!-- http://www.tja.ee/public/Legislation_side/Numbering_/Estonian_NP_eng.htm -->
     <territory id="EE" countryCode="372" internationalPrefix="00">
       <availableFormats>
-        <numberFormat pattern="([34-79]\d{2})(\d{4})">
+        <numberFormat pattern="([3-79]\d{2})(\d{4})">
           <leadingDigits>
             [369]|
             4[3-8]|
              1(?:
                0[0169]|
                1[124]|
-               2[0278]|
+               2[0-278]|
                5[0-2]
              )|
              [89]00
            </leadingDigits>
            <format>$1 $2 $3</format>
          </numberFormat>
-         <numberFormat pattern="(\d{2})(\d{7})">
+         <numberFormat pattern="(\d{2})(\d{6,7})">
            <leadingDigits>
-             13|
+             1(?:
+               3|
+               5[23]
+             )|
              [4-6]|
              [89][2-9]
            </leadingDigits>
         <possibleNumberPattern>\d{5,10}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
-        <!-- Short numbers used for businesses (starting with 16 or 19) are covered here. -->
-        <nationalNumberPattern>
-          (?:
-            1[35][23]|
-            2[23]\d|
-            3\d|
-            4(?:
-              0[2-4]|
+        <!-- Short numbers used for businesses (starting with 16 or 19) are covered here. Note also
+             that the plan says numbers starting with 15 should be followed by seven digit
+             subscriber numbers, but all numbers we have found online are in fact six digit.
+             Subscriber numbers starting with 5 are also permitted for the area codes 040, with 5, 6
+             and 7 for the area code 050, with 5 and 7 for 082, with 6 for 084, with 7 for 086 and
+             092 and with 5 and 6 for 96. -->
+        <nationalNumberPattern>
+          (?:
+            1(
+              3[23]\d|
+              5[23]
+            )|
+            2[2-4]\d{2}|
+            3\d{2}|
+            4(?:
+              0[2-5]|
               [578][23]|
               64
-            )|
-            5(?:
-              0[234]|
+            )\d|
+            5(?:
+              0[2-7]|
               [57][23]
-            )|
-            6[24-689]3|
-            8(?:
-              [28][2-4]|
-              42|
-              6[23]
-            )|
-            9(?:
-              [25]2|
+            )\d|
+            6[24-689]3\d|
+            8(?:
+              2[2-57]|
+              4[26]|
+              6[237]|
+              8[2-4]
+            )\d|
+            9(?:
+              2[27]|
               3[24]|
-              6[23]|
+              52|
+              6[2356]|
               7[2-4]
-            )
-          )\d{6}|
+            )\d
+          )\d{5}|
           1[69]\d{3}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{5,9}</possibleNumberPattern>
       </fixedLine>
       <mobile>
         <!-- Egypt is switching to a 10-digit pattern on October 6th. This will run in parallel with
-             the old pattern for three months, so we support both here in the meantime. -->
+             the old pattern for three months, so we support both here in the meantime. Adding the
+             extra prefix 121 from user reports that Mobinil has started allocating numbers
+             beginning with this prefix. -->
         <nationalNumberPattern>
           1(?:
             [0-246-9]|
           1(?:
             0[0169]|
             1[124]|
-            2[0278]
+            2[0-278]
           )\d{7}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{9,10}</possibleNumberPattern>
               4(?:
                 1[69]|
                 3[2-49]|
-                4[0-23]|
+                4[0-3]|
                 6[5-8]
               )|
               5(?:
               2[89]|
               3[35-9]|
               4[01]|
-              5[0-347-9]|
+              5[0-47-9]|
               [67]\d|
               8[457-9]|
               9[0146]
         <exampleNumber>7640123456</exampleNumber>
       </pager>
       <!-- Source for non geographic numbers:
-           http://en.wikipedia.org/wiki/Non-geographical_telephone_numbers_in_the_UK -->
+           http://en.wikipedia.org/wiki/Non-geographic_telephone_numbers_in_the_United_Kingdom -->
       <tollFree>
         <!-- 800 1111 with 7 digits, 800 with 9 or 10 digits, 808 with 10 digits, 500 with 9 digits. -->
         <nationalNumberPattern>
                nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
       <availableFormats>
         <numberFormat pattern="(\d{2})(\d{3})(\d{4})">
-            <format>$1 $2 $3</format>
-        </numberFormat>
-      </availableFormats>
-      <generalDesc>
-        <nationalNumberPattern>[235]\d{6,8}</nationalNumberPattern>
+          <leadingDigits>[235]</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <numberFormat pattern="(\d{3})(\d{5})">
+          <leadingDigits>8</leadingDigits>
+          <format>$1 $2</format>
+        </numberFormat>
+      </availableFormats>
+      <generalDesc>
+        <nationalNumberPattern>
+          [235]\d{8}|
+          8\d{7}
+        </nationalNumberPattern>
         <possibleNumberPattern>\d{7,9}</possibleNumberPattern>
       </generalDesc>
+      <noInternationalDialling>
+        <nationalNumberPattern>800\d{5}</nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
+        <exampleNumber>80012345</exampleNumber>
+      </noInternationalDialling>
       <fixedLine>
         <nationalNumberPattern>
           3(?:
         <possibleNumberPattern>\d{9}</possibleNumberPattern>
         <exampleNumber>231234567</exampleNumber>
       </mobile>
-      <!-- No tollFree or premiumRate information can be found. -->
+      <tollFree>
+        <!-- Found online references to these numbers, although they are not in the plan since they
+             are not internationally diallable. -->
+        <nationalNumberPattern>800\d{5}</nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
+        <exampleNumber>80012345</exampleNumber>
+      </tollFree>
+      <!-- No premiumRate information can be found. -->
       <emergency>
         <nationalNumberPattern>
           19[123]|
         <exampleNumber>21234567</exampleNumber>
       </fixedLine>
       <mobile>
-        <nationalNumberPattern>[5-79]\d{7}</nationalNumberPattern>
+        <nationalNumberPattern>[569]\d{7}</nationalNumberPattern>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
         <exampleNumber>51234567</exampleNumber>
       </mobile>
+      <pager>
+        <nationalNumberPattern>7\d{7}</nationalNumberPattern>
+        <possibleNumberPattern>\d{8}</possibleNumberPattern>
+        <exampleNumber>71234567</exampleNumber>
+      </pager>
       <tollFree>
         <nationalNumberPattern>800\d{6}</nationalNumberPattern>
         <possibleNumberPattern>\d{9}</possibleNumberPattern>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
+        <!-- Extra prefixes 228X and 2292 were added from numbers found online.  -->
         <nationalNumberPattern>
           2(?:
             2(?:
               [23]\d|
               4[056]|
               5[57]|
-              9[01]
+              8[0146-9]|
+              9[012]
             )|
             4(?:
               2|3-59]|
         <!-- Area codes taken from wikipedia, with missing ones added from
              http://www.telkom.co.id/customer-services/area-and-country-code/?type=area.
              We also added 0770 after user feedback because it seems to be used on Bintan island.
-             -->
-        <nationalNumberPattern>
-          2[124]\d{7,8}|
+             Where known, fixed mobile prefixes have been represented as Mobile. -->
+        <nationalNumberPattern>
+          2(?:
+            1(?:
+              [0-8]\d{6,7}|
+              9\d{6}
+            )|
+            [24]\d{7,8}
+          )|
           (?:
             2(?:
               [35][1-4]|
               6[1-8]
             )|
             6(?:
-              19? |
+              19?|
               [25]\d|
               3[1-469]|
               4[1-6]
             )|
             9(?:
               0[12]|
-              1[0134-8]|
+              1[013-8]|
               2[0-479]|
               5[125-8]|
               6[23679]|
         <exampleNumber>612345678</exampleNumber>
       </fixedLine>
       <mobile>
-        <nationalNumberPattern>8[1-35-9]\d{7,9}</nationalNumberPattern>
+        <!-- It is unclear exactly which prefixes could be mobile phones, based on the information
+             on the wikipedia page. However, Bakrie have provided a list of their prefixes, which
+             are captured below. The pattern covers the area code plus the first one-two digits of
+             the subscriber number. -->
+        <nationalNumberPattern>
+          (?:
+            2(?:
+              1(?:
+                3[145]|
+                4[01]|
+                5[1-469]|
+                60|
+                8[0359]|
+                9\d
+              )|
+              2(?:
+                88|
+                9[1256]
+              )|
+              3[1-4]9|
+              4(?:
+                36|
+                91
+              )|
+              5(?:
+                1[349]|
+                [2-4]9
+              )|
+              6[0-7]9|
+              7(?:
+                [1-36]9|
+                4[39]
+              )|
+              8[1-5]9|
+              9[1-48]9
+            )|
+            3(?:
+              19[1-3]|
+              2[12]9|
+              3[13]9|
+              4(?:
+                1[69]|
+                39
+              )|
+              5[14]9|
+              6(?:
+                1[69]|
+                2[89]
+              )|
+              709
+            )|
+            4[13]19|
+            5(?:
+              1(?:
+                19|
+                8[39]
+              )|
+              4[129]9|
+              6[12]9
+            )|
+            6(?:
+              19[12]|
+              2(?:
+                [23]9|
+                77
+              )
+            )|
+            7(?:
+              1[13]9|
+              2[15]9|
+              419|
+              5(?:
+                1[89]|
+                29
+              )|
+              6[15]9|
+              7[178]9
+            )
+          )\d{5,6}|
+          8[1-35-9]\d{7,9}
+        </nationalNumberPattern>
         <possibleNumberPattern>\d{9,11}</possibleNumberPattern>
         <exampleNumber>812345678</exampleNumber>
       </mobile>
       </noInternationalDialling>
       <fixedLine>
         <!-- This is a list of the 2 and 3 digit area codes and the first 3 digits of 4 digit area
-             codes, so we can check the following digit belongs to one of the operator-codes (2-6).
+             codes, so we can check the following digit belongs to one of the operator-codes (2-7).
              Operator codes are from wikipedia, with the addition of 5 (HFCL Infotel in some areas).
+             Not all operator codes are available in all areas, but we don't maintain that
+             distinction here.
              Area codes starting with a 7 are listed separately, since the prefixes need to be more
              detailed so they clash less with mobile phone prefixes. -->
         <nationalNumberPattern>
             33|
             4[04]|
             79
-          )[2-6]\d{7}|
-          80[2-46]\d{7}|
+          )[2-7]\d{7}|
+          80[2-467]\d{7}|
           (?:
             1(?:
               2[0-249]|
               8[34]|
               91
             )
-          )[2-6]\d{6}|
+          )[2-7]\d{6}|
           (?:
             (?:
               1(?:
                 2[2457]|
                 3[2-4]|
                 4[235-7]|
-                5[2-689]|
+                [57][2-689]|
                 6[24-58]|
-                7[23-689]|
                 8[1-6]
               )|
               8(?:
                 [013-8]\d
               )
             )
-          )[2-6]\d{5}
+          )[2-7]\d{5}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{6,10}</possibleNumberPattern>
         <exampleNumber>1123456789</exampleNumber>
               9[1-578]
             )|
             2(?:
-              2[034-9]|
+              2[03-9]|
               3[3-58]|
               4[0-468]|
               5[04-8]|
             9(?:
               [23]0|
               4[02-46-9]|
-              5[0245-79]|
+              5[024-79]|
               6[4-9]|
               7[2-47-9]|
               8[02-7]|
                 9[2-8]
               )|
               3(?:
-                7[2-56]|
+                7[2-6]|
                 [3-6][2-9]|
                 8[2-5]
               )|
             9(?:
               [23]0|
               4[02-46-9]|
-              5[0245-79]|
+              5[024-79]|
               6[4-9]|
               7[2-47-9]|
               8[02-7]|
             9(?:
               [23]0|
               4[02-46-9]|
-              5[0245-79]|
+              5[024-79]|
               6[4-9]|
               7[2-47-9]|
               8[02-7]|
             9(?:
               [23]0|
               4[02-46-9]|
-              5[0245-79]|
+              5[024-79]|
               6[4-9]|
               7[2-47-9]|
               8[02-7]|
             1|
             2(?:
               23|
-              5[5-89]|
+              5[5-9]|
               64|
               78|
               8[39]|
 
     <!-- Kenya -->
     <!-- http://www.cck.go.ke/licensing/numbering/plan.html -->
+    <!-- http://en.wikipedia.org/wiki/+254 -->
     <territory id="KE" countryCode="254" internationalPrefix="000"
                nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
       <availableFormats>
       </availableFormats>
       <generalDesc>
         <nationalNumberPattern>
-          20\d{4,7}|
-          [4-9]\d{5,9}
-        </nationalNumberPattern>
-        <possibleNumberPattern>\d{4,10}</possibleNumberPattern>
-      </generalDesc>
-      <fixedLine>
-        <nationalNumberPattern>
-          (?:
-            20|
-            4[0-6]|
-            5\d|
-            6[0-24-9]
-          )\d{4,7}
-        </nationalNumberPattern>
-        <possibleNumberPattern>\d{4,9}</possibleNumberPattern>
+          20\d{6,7}|
+          [4-9]\d{6,9}
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5,10}</possibleNumberPattern>
+      </generalDesc>
+      <fixedLine>
+        <!-- The prefix 066 is supposed to be used only for 9-digit numbers, but none of these can
+             be found online, and the plan says also it is migrating to 9 digit numbers. Both are
+             supported for now. -->
+        <nationalNumberPattern>
+          20\d{6,7}|
+          4(?:
+            [013]\d{7}|
+            [24-6]\d{5,7}
+          )|
+          5(?:
+            [0-36-8]\d{5,7}|
+            [459]\d{5}
+          )|
+          6(?:
+            [08]\d{5}|
+            [14-79]\d{5,7}|
+            2\d{7}
+          )
+        </nationalNumberPattern>
+        <possibleNumberPattern>\d{5,9}</possibleNumberPattern>
         <exampleNumber>202012345</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- Adding 70[3-5], 754 and 775 after successful delivery of SMSs. -->
         <nationalNumberPattern>
           7(?:
-            0[0-5]|
+            0[0-8]|
             [123]\d|
-            5[0-4]|
+            5[0-5]|
             7[0-5]|
-            8[6-9]
+            8[5-9]
           )\d{6}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{9}</possibleNumberPattern>
       </mobile>
       <tollFree>
         <!-- Longer numbers have been found than the plan suggests, so we support them here too. -->
-        <nationalNumberPattern>800[245-8]\d{5,6}</nationalNumberPattern>
+        <nationalNumberPattern>800[24-8]\d{5,6}</nationalNumberPattern>
         <possibleNumberPattern>\d{9,10}</possibleNumberPattern>
         <exampleNumber>800223456</exampleNumber>
       </tollFree>
       <premiumRate>
-        <nationalNumberPattern>
-          9(?:
-            00[2-578]|
-            11\d
-          )\d{5}
-        </nationalNumberPattern>
+        <nationalNumberPattern>900[02-578]\d{5}</nationalNumberPattern>
         <possibleNumberPattern>\d{9}</possibleNumberPattern>
         <exampleNumber>900223456</exampleNumber>
       </premiumRate>
       <shortCode>
-        <nationalNumberPattern>
-          1(?:
-            0[089]|
+        <!-- Excluding SMS-only premium-rate short codes for now. -->
+        <nationalNumberPattern>
+          1(?:
+            0[09]|
             1(?:
               [06]|
-              99
-            )|
-            2[123]|
-            3[013]|
-            4[14]|
-            501
+              9[0-2579]
+            )|
+            2[13]|
+            3[01]
           )
         </nationalNumberPattern>
         <possibleNumberPattern>\d{3,4}</possibleNumberPattern>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[356-8]\d{8,9}</nationalNumberPattern>
+        <nationalNumberPattern>[35-8]\d{8,9}</nationalNumberPattern>
         <possibleNumberPattern>\d{5,10}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
             (?:
               1[0-35-9]|
               6[6-9]|
-              7[06-89]
+              7[06-9]
             )[1-9]|
             8(?:
               0[89]|
                nationalPrefix="0" nationalPrefixForParsing="0(8[1-46-8]|85\d{2})?"
                nationalPrefixFormattingRule="$NP$FG" carrierCodeFormattingRule="$NP$CC-$FG">
       <availableFormats>
+        <numberFormat pattern="(\d{3})" nationalPrefixFormattingRule="$FG">
+          <leadingDigits>11[29]</leadingDigits>
+          <format>$1</format>
+        </numberFormat>
         <numberFormat pattern="(\d{2})(\d{4})(\d{4})">
           <leadingDigits>
             1(?:
         <nationalNumberPattern>
           (?:
             5(?:
-              0[0-26]|
+              0[0-2568]|
               5\d
             )|
             6(?:
         <nationalNumberPattern>[3589]\d{9}</nationalNumberPattern>
         <possibleNumberPattern>\d{7}(?:\d{3})?</possibleNumberPattern>
       </generalDesc>
-      <fixedLine>
+      <!-- The 800 NXX code is listed as being "national only", but we successfully reached numbers
+           from Switzerland with this prefix so do not list it as noInternationalDialling. -->
+      <fixedLine>
+        <!-- The Westtel numbers in the plan seem now to be live and assigned to fixed-line phones,
+             as per numbers found online and their website www.logic.ky. -->
         <nationalNumberPattern>
           345(?:
             2(?:
               40
             )|
             7(?:
+              4[35-79]|
               6[6-9]|
               77
             )|
               00|
               1[45]|
               25|
-              4[89]|
-              88
+              [48]8
             )|
             9(?:
               14|
         <exampleNumber>3452221234</exampleNumber>
       </fixedLine>
       <mobile>
+        <!-- Adding central office codes 321, 322, 328, 576, 923 & 936 from numbers found online.
+             Most central office codes that were surrendered have not been included, with the
+             exception of 546 where numbers have been found. -->
         <nationalNumberPattern>
           345(?:
-            32[3-79]|
-            5(?:
-              1[467]|
+            32[1-9]|
+            5(?:
+              1[67]|
               2[5-7]|
-              4[5-9]
-            )|
-            9(?:
-              1[679]|
-              2[4-9]|
-              3[89]
+              4[6-8]|
+              76
+            )|
+            9(?:
+              1[67]|
+              2[3-9]|
+              3[689]
             )
           )\d{4}
         </nationalNumberPattern>
         <possibleNumberPattern>\d{10}</possibleNumberPattern>
         <exampleNumber>3453231234</exampleNumber>
       </mobile>
+      <pager>
+        <nationalNumberPattern>345849\d{4}</nationalNumberPattern>
+        <possibleNumberPattern>\d{10}</possibleNumberPattern>
+        <exampleNumber>3458491234</exampleNumber>
+      </pager>
       <tollFree>
         <nationalNumberPattern>
           8(?:
             [89][01]|
             7(?:
               [01]|
-              6[01346-9])
+              6[013-9])
           </leadingDigits>
           <format>$1 $2 $3</format>
         </numberFormat>
             3\d|
             7(?:
               [01]\d|
-              6[01346-9]
+              6[013-9]
             )
           )\d{5}
         </nationalNumberPattern>
         <!-- Patterns overlap because of variable number length. -->
         <numberFormat pattern="(\d{2})(\d{3})">
           <leadingDigits>
-            [23-5]|
+            [2-5]|
             7[1-9]|
             [89](?:
               [1-9]|
         </numberFormat>
         <numberFormat pattern="(\d{2})(\d{2})(\d{2})">
           <leadingDigits>
-            [23-5]|
+            [2-5]|
             7[1-9]|
             [89](?:
               [1-9]|
         <exampleNumber>520123456</exampleNumber>
       </fixedLine>
       <mobile>
+        <!-- Prefixes 60[1-5], 62[79], 63[0458] and 680 are from numbers found online, bug-reports,
+             and information provided directly by the carriers. -->
         <nationalNumberPattern>
           6(?:
-            0[0-36]|
+            0[0-6]|
             [14-7]\d|
-            2[236]|
-            3[348]|
+            2[23679]|
+            3[03458]|
+            80|
             99
           )\d{6}
         </nationalNumberPattern>
         </numberFormat>
       </availableFormats>
       <generalDesc>
-        <nationalNumberPattern>[256-9]\d{7}</nationalNumberPattern>
+        <nationalNumberPattern>[25-9]\d{7}</nationalNumberPattern>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
         <possibleNumberPattern>\d{8}</possibleNumberPattern>
       </generalDesc>
       <fixedLine>
+        <!-- Extra prefix 02 60 added from numbers found online. -->
         <nationalNumberPattern>
           (?:
             2(?:
               [23]\d|
               5[125]|
-              61
+              6[01]
             )|
             3(?:
               1[3-6]|
               17|
               2(?:
                 [0189]\d|
-                [23-6]|
+                [2-6]|
                 7\d?
               )|
               3(?:
         <exampleNumber>20201234</exampleNumber>
       </fixedLine>
       <mobile>
-        <!-- Added 90, 91, 97 & 98 from online data. Zain have confirmed that they use the 97
-             prefix. -->
-        <nationalNumberPattern>9[0134678]\d{6}</nationalNumberPattern>
+        <!-- Added 90, 91, 92, 97, 98 & 99 from online data. Airtel have confirmed that they use the
+             97 prefix, and Orange use 92. -->
+        <nationalNumberPattern>9[0-46-9]\d{6}</nationalNumberPattern>
         <exampleNumber>93123456</exampleNumber>
       </mobile>
       <tollFree>
                preferredInternationalPrefix="00" nationalPrefix="0"
                nationalPrefixFormattingRule="$NP$FG">
       <availableFormats>
+        <!-- Pattern for fixed-line formats. -->
         <numberFormat pattern="([34679])(\d{3})(\d{4})">
           <leadingDigits>
             [3467]|
           </leadingDigits>
           <format>$1-$2 $3</format>
         </numberFormat>
-        <!-- Mobile numbers do not have exclusive leading digits - formatting depends on number
-             length. -->
-        <!-- Vodafone numbers are formatted with 021 separated. -->
-        <numberFormat pattern="(21)(\d{4})(\d{3,4})">
-          <leadingDigits>21</leadingDigits>
-          <format>$1 $2 $3</format>
-        </numberFormat>
-        <!-- 2Degrees numbers are formatted with 022 separated, since this seems to be more common
-             than writing the first group as 022X based on Google web searches, and is used by
-             2Degrees themselves. See formatting on www.2degreesmobile.co.nz for an example of the
-             latter. -->
-        <numberFormat pattern="(22)(\d{3})(\d{4})">
-          <leadingDigits>22</leadingDigits>
-          <format>$1 $2 $3</format>
-        </numberFormat>
-        <numberFormat pattern="([2589]\d{2})(\d{3})(\d{3,4})">
-          <!-- Note no online 022 numbers can be found that are 10 digits long, but the numbering
-               plan states they are possible, so we format them in this fashion if we see them. -->
-          <!-- Adding in the toll free numbers here as well since they follow the same format. -->
-          <leadingDigits>
-            2[0247-9]|
-            5|
-            [89]00
-          </leadingDigits>
-          <format>$1 $2 $3</format>
-        </numberFormat>
-        <!-- Vodafone and Orcon numbers can also be 8 digits (without leading 0), and these are
-             formatted differently. -->
-        <numberFormat pattern="(\d{2})(\d{3})(\d{3,4})">
-          <leadingDigits>2[0169]|86</leadingDigits>
-          <format>$1 $2 $3</format>
-        </numberFormat>
-        <!-- Antarctica -->
+        <!-- Area code for NZ's Scott Base, in Antarctica. -->
         <numberFormat pattern="(24099)(\d{3})">
           <leadingDigits>240</leadingDigits>
           <leadingDigits>2409</leadingDigits>
           <leadingDigits>24099</leadingDigits>
           <format>$1 $2</format>
         </numberFormat>
+        <!-- Mobile numbers do not have exclusive leading digits - formatting depends on number
+             length. -->
+        <!-- Vodafone numbers can be 8 digits (without leading 0). -->
+        <numberFormat pattern="(\d{2})(\d{3})(\d{3})">
+          <leadingDigits>21</leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <!-- Paging numbers and some mobile numbers (Telecom/Vodafone/TelstraClear). -->
+        <numberFormat pattern="(\d{2})(\d{3})(\d{3,4})">
+          <leadingDigits>
+            2(?:
+              1[1-9]|
+              [69]|
+              7[0-35-9]
+            )|
+            86
+          </leadingDigits>
+          <format>$1 $2 $3</format>
+        </numberFormat>
+        <!-- 2Degrees numbers are formatted with 022 separated, since this seems to be more common
+             than writing the first group as 022X based on Google web searches, and is used by
+             2Degrees themselves. See formatting on www.2degreesmobile.co.nz for an example of the
+             latter. We follow the same pattern for 020 (Orcon) and 028 (mixed) numbers. -->
+        <numberFormat pat