diff --git a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml index 0e72c87b8..862dd9a33 100644 --- a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml +++ b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml @@ -479,12 +479,16 @@ + nationalPrefix="0"> $1 $2 $3 - $1 $2 $3 + $1 $2 $3 $1 $2 $3 $1 $2 $3 @@ -542,10 +546,10 @@ - $1 $2 + $1 $2 - [57-9]\d{6} + [5-9]\d{6} \d{7} @@ -553,7 +557,10 @@ 5212345 - (?:5[69]\d|9(?:6\d|9[02-9])|7[34]\d)\d{4} + + (?:5[69]\d|660|9(?:6\d|9[02-9])|7[34]\d)\d{4} 5601234 @@ -702,7 +709,9 @@ 20491234 - 7(?:[0168]\d|2[0-4]|4[01]|5[01346-9])\d{5} + + 7(?:[01568]\d|2[0-4]|4[01]|5[01346-9])\d{5} 70123456 @@ -769,10 +778,10 @@ - - (?:2955|7(?:9(?:5[6-9]|[19]\d)|(?:6[269]|77|8\d)\d))\d{4} + (?:29\d|7(?:1[1-3]|[4-9]\d))\d{5} 79561234 @@ -785,7 +794,7 @@ - [289]\d{7}|7\d{3} + [2689]\d{7}|7\d{3} \d{4,8} @@ -798,8 +807,11 @@ - 9(?:0[069]|[35][0-2457-9]|7[014-9])\d{5} + of these prefixes can be found. 9[68] and 97[23] prefixes have also been + added because of online numbers following these patterns and numbers + where SMSs were successfully delivered. + 66 has been also added, as it seems to be a prefix for Mobile MTN. --> + 66\d{6}|9(?:0[069]|[35][0-2457-9]|[6-8]\d)\d{5} \d{8} 90011234 @@ -892,7 +904,7 @@ ($1) $2-$3 - $1-$2 + $1-$2 $1 $2 $3 @@ -901,7 +913,7 @@ \d{8,10} - 400\d{5}|(?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-5]\d{7} + (?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-5]\d{7} 1123456789 @@ -917,6 +929,10 @@ [359]00\d{6,7} 300123456 + + (?:400\d|3003)\d{4} + 40041234 + @@ -1048,7 +1064,29 @@ - + + + + $1 $2 $3 + $1 $2 + + + [89]\d{8}|[1-6]\d{6} + \d{7,9} + + + [1-6]\d{6} + \d{7} + 1234567 + + + (?:8[0149]|9[7-9])\d{7} + \d{9} + 991234567 + @@ -1158,7 +1196,8 @@ 21234567 - (?:0[1-9]|4[4-9]|50|6[067])\d{6} + + (?:0[1-9]|4[04-9]|50|6[067])\d{6} 01234567 @@ -1357,7 +1396,10 @@ 2211234 - 9[189]\d{5} + + 9[157-9]\d{5} 9911234 @@ -1532,7 +1574,7 @@ - + $1 $2 $3 $4 @@ -1546,7 +1588,9 @@ 32123456 - (?:2[0-9]|3[01]|4[0-2]|5[0-3]|6[01])\d{6} + + (?:2[0-9]|3[0-2]|4[0-2]|5[0-3]|6[01]|72|99)\d{6} 20123456 @@ -1616,8 +1660,56 @@ + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + + $1 $2 $3 $4 + $1 $2 $3 $4 + $1 $2 $3 $4 + + + (?:[1-4]|[5-9]\d)\d{7} + \d{8,9} + + + + (?:1\d|2[014-79]|3[0-8]|4[0135689])\d{6}|9619\d{5} + 12345678 + + + (?:5[56]|6[69]|7[79])\d{7} + \d{9} + 551234567 + + + 800\d{6} + \d{9} + 800123456 + + + + 80[12]1\d{5} + \d{9} + 801123456 + + + 80[3-689]1\d{5} + \d{9} + 808123456 + + + 98[23]\d{6} + \d{9} + 983123456 + @@ -2132,8 +2224,26 @@ - + + + + $1 $2 $3 $4 + + + [367]\d{7} + \d{8} + + + 30(?:24|3[12]|4[1-35-7]|5[13]|6[189]|[78]1|9[1478])\d{4} + 30241234 + + + + 6(?:0(?:2\d|3[3467]|5[2457-9])|[2457]\d{2}|3(?:[14]0|35))\d{4} + 60201234 + @@ -2298,6 +2408,10 @@ \d{11} 90012345678 + + 8[1-3]\d{6} + \d{8} + @@ -2434,9 +2548,10 @@ - 2[124]\d{7,8}|(?:2(?:[35][1-4]|6[0-8]|7[1-6]|8\d|9[1-8])|3(?:1|2[1-578]|3[1-68]|4[1-3]|5[1-8]|6[1-3568]|7[0-46]|8\d)|4(?:0[1-589]|1[01347-9]|2[0-36-8]|3[0-24-68]|5[1-378]|6[1-5]|7[134]|8[1245])|5(?:1[1-35-9]|2[25-8]|3[1246-9]|4[1-3589]|5[1-46]|6[1-8])|6(?:19?|[25]\d|3[1-469]|4[1-6])|7(?:1[1-46-9]|2[14-9]|[36]\d|4[1-8]|5[1-9]|7[1-36-9])|9(?:0[12]|1[0134-8]|2[0-479]|5[125-8]|6[23679]|7[159]|8[01346]))\d{5,8} + 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. --> + 2[124]\d{7,8}|(?:2(?:[35][1-4]|6[0-8]|7[1-6]|8\d|9[1-8])|3(?:1|2[1-578]|3[1-68]|4[1-3]|5[1-8]|6[1-3568]|7[0-46]|8\d)|4(?:0[1-589]|1[01347-9]|2[0-36-8]|3[0-24-68]|5[1-378]|6[1-5]|7[134]|8[1245])|5(?:1[1-35-9]|2[25-8]|3[1246-9]|4[1-3589]|5[1-46]|6[1-8])|6(?:19?|[25]\d|3[1-469]|4[1-6])|7(?:1[1-46-9]|2[14-9]|[36]\d|4[1-8]|5[1-9]|7[0-36-9])|9(?:0[12]|1[0134-8]|2[0-479]|5[125-8]|6[23679]|7[159]|8[01346]))\d{5,8} \d{5,10} 612345678 @@ -2607,38 +2722,40 @@ - $1 $2 $3 - - $1 $2 $3 - - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - - - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 + + $1 $2 $3 + + $1 $2 $3 + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 [1-9]\d{9,10} @@ -2648,16 +2765,20 @@ - (?:11|2[02]|33|4[04]|79|80)[2-6]\d{7}|(?:1(?:2[0-249]|3[0-25]|4[145]|5[14]|6[014]|7[1257]|8[01346]|9[14])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[126-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[25]|22|3[25]|4[28]|5[12]|6[25]|[78]1|9[15])|6(?:12|[2345]1|57|6[13]|7[14]|80)|7(?:12|2[14]|3[134]|4[47]|5[15]|[67]1|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91))[2-6]\d{6}|(?:1(?:2[35-8]|3[346-9]|4[236-9]|5[0235-9]|6[235-9]|7[34689]|8[257-9]|9[0235-9])|2(?:1[134689]|3[24-8]|4[2-8]|5[25689]|6[2-4679]|7[13-79]|8[2-479]|9[235-9])|3(?:01|1[79]|2[1-5]|4[25-8]|5[125689]|6[235-7]|7[157-9]|8[2-467])|4(?:1[14578]|2[5689]|3[2-467]|5[4-7]|6[35]|73|8[2689]|9[2389])|5(?:1[146-9]|2[14-8]|3[1346]|4[14-69]|5[46]|6[146-9]|7[2-4]|8[2-8]|9[246])|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24-58]|7[23-689]|8[1-6])|7(?:1[013-9]|2[0235-9]|3[2679]|4[1-35689]|5[2-46-9]|[67][02-9]|8[0-8]|9\d)|8(?:1[1357-9]|2[235-8]|3[03-57-9]|4[0-24-9]|5\d|6[2457-9]|7[1-6]|8[1256]|9[2-4]))\d[2-6]\d{5} + wikipedia, with the addition of 5 (HFCL Infotel). Area codes starting + with a 7 are listed separately, since the prefixes need to be more + detailed as they would otherwise clash with mobile phone prefixes. --> + (?:11|2[02]|33|4[04]|79|80)[2-6]\d{7}|(?:1(?:2[0-249]|3[0-25]|4[145]|5[14]|6[014]|7[1257]|8[01346]|9[14])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[126-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[25]|22|3[25]|4[28]|5[12]|6[25]|[78]1|9[15])|6(?:12|[2345]1|57|6[13]|7[14]|80)|7(?:12|2[14]|3[134]|4[47]|5[15]|[67]1|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91))[2-6]\d{6}|(?:(?:1(?:2[35-8]|3[346-9]|4[236-9]|5[0235-9]|6[235-9]|7[34689]|8[257-9]|9[0235-9])|2(?:1[134689]|3[24-8]|4[2-8]|5[25689]|6[2-4679]|7[13-79]|8[2-479]|9[235-9])|3(?:01|1[79]|2[1-5]|4[25-8]|5[125689]|6[235-7]|7[157-9]|8[2-467])|4(?:1[14578]|2[5689]|3[2-467]|5[4-7]|6[35]|73|8[2689]|9[2389])|5(?:1[146-9]|2[14-8]|3[1346]|4[14-69]|5[46]|6[146-9]|7[2-4]|8[2-8]|9[246])|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24-58]|7[23-689]|8[1-6])|8(?:1[1357-9]|2[235-8]|3[03-57-9]|4[0-24-9]|5\d|6[2457-9]|7[1-6]|8[1256]|9[2-4]))\d|7(?:(?:1[013-9]|2[0235-9]|3[2679]|4[1-35689]|5[2-46-9]|[67][02-9]|9\d)\d|8(?:2[0-6]|[013-8]\d)))[2-6]\d{5} \d{6,10} 1123456789 - - (?:9\d(?:0(?:0[1-9]|9[0-8]|[1-8]\d)|[1-9]\d{2})|8(?:0[01589]|1[024]|80)\d{2})\d{5} + (?:7(?:39[89]|5(?:50|6[6-8]|79|[89][7-9])|6(?:0[027]|20|3[19]|54|65|7[67]|9[6-9])|7(?:0[89]|3[589]|42|60|9[5-9])|8(?:[03][07-9]|14|2[7-9]|4[25]|6[09]))\d|9\d{4}|8(?:0[01589]\d|1[024]\d|8(?:[079]\d|44)|9[057-9]\d)\d)\d{5} \d{10} 9123456789 @@ -2822,7 +2943,8 @@ 8765123456 - 876(?:(?:21|3[02-9]|[48]\d|5[78]|77)\d|7(?:0[07]|8[1-47-9]|9[0-36-9])|9(?:[01]9|9[0579]))\d{4} + + 876(?:(?:21|[348]\d|5[78]|77)\d|7(?:0[07]|8[1-47-9]|9[0-36-9])|9(?:[01]9|9[0579]))\d{4} \d{10} 8762101234 @@ -2840,12 +2962,15 @@ + + $1 $2 $3 - $1 $2 $3 + $1 $2 $3 $4 $5 $1 $2 $1 $2 @@ -2860,7 +2985,9 @@ 62345678 - 7(?:4[5-7]|7[569]|8[5-8]|9[05-7])\d{6} + + 7(?:4[5-7]|7[5-79]|8[5-8]|9[05-9])\d{6} \d{9} 790123456 @@ -2952,8 +3079,7 @@ - - + @@ -2969,10 +3095,11 @@ (?:20|4[0-6]|5\d|6[0-24-9])\d{4,7} \d{4,9} - 201234 + 202012345 - 7(?:1[0-5]|2\d|3[2-8]|5[0-2]|7[023])\d{6} + + 7(?:1[0-6]|2\d|3[2-8]|5[0-2]|7[023])\d{6} \d{9} 712123456 @@ -3009,7 +3136,9 @@ 312123456 - 5[124-7]\d{7}|7(?:00|7\d)\d{6} + + 5[124-7]\d{7}|7(?:0[05]|7\d)\d{6} \d{9} 700123456 @@ -3026,13 +3155,13 @@ - $1 $2 $3 $1 $2 $3 - [1-79]\d{7,9} + [1-9]\d{7,9} \d{6,10} @@ -3041,7 +3170,9 @@ 23456789 - (?:1[0-25689]|9[1-49])[2-9]\d{5} + + (?:(?:1[0-35-9]|9[1-49])[1-9]|85[2-689])\d{5} \d{8} 91234567 @@ -3121,35 +3252,56 @@ - + + + + - $1-$2-$3 - $1-$2-$3 - $1-$2 - $1-$2-$3 - $1-$2-$3 - $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3-$4 + $1-$2-$3 + $1-$2-$3 + $1-$2 + $1-$2 + $1-$2 + $1-$2 [1-79]\d{3,9}|8\d{8} \d{4,10} - - 2(?:1\d{2,3}|[2367]\d{6,7}|[4589]\d{6})|(?:[34][1-3]|5[13-5]|6[124])\d{7}|(?:52|63)\d{7,8} + (?:2|[34][1-3]|5[1-5]|6[1-4])(?:1\d{2,3}|[2-9]\d{6,7}) \d{4,10} 22123456 - 1[0-26-9]\d{5,7} - \d{7,9} - 12345678 + 1[0-25-9]\d{7,8} + \d{9,10} + 1023456789 80\d{7} @@ -3157,19 +3309,19 @@ 801234567 - 60\d{7,8} - \d{9,10} - 601234567 + 60[2-9]\d{6} + \d{9} + 602345678 - 50\d{7,8} - \d{9,10} - 501234567 + 50\d{8} + \d{10} + 5012345678 - 70\d{7,8} - \d{9,10} - 701234567 + 70\d{8} + \d{10} + 7012345678 @@ -3268,7 +3420,7 @@ nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> $1 $2 $3 $4 + pattern="(20)([2357-9])(\d{3})(\d{3})">$1 $2 $3 $4 $1 $2 $3 @@ -3282,7 +3434,9 @@ 21212862 - 20[2579]\d{6} + + 20[2357-9]\d{6} \d{9} 202345678 @@ -3290,8 +3444,44 @@ + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + + + [13-9]\d{6,7} + \d{7,8} + + + (?:[14-6]\d|[7-9][2-9])\d{5} + \d{7} + 1123456 + + + + (3\d|7(?:0\d|1[167]))\d{5} + \d{7,8} + 71123456 + + + 8[01]\d{6} + \d{8} + 80123456 + + + 9[01]\d{6} + \d{8} + 90123456 + @@ -3307,7 +3497,9 @@ 7582345678 - 758(?:28[4-7]|384|4(?:6[01]|8[4-9])|5(?:1[89]|20|84)|7(?:1[2-9]|2[034]))\d{4} + + 758(?:28[4-7]|384|4(?:6[01]|8[4-9])|5(?:1[89]|20|84)|7(?:1[2-9]|2[0-4]))\d{4} \d{10} 7582845678 @@ -3407,8 +3599,28 @@ - + + + + + $1 $2 + + + [2568]\d{7} + \d{8} + + + 2\d{7} + 22123456 + + + [56]\d{7} + 50123456 + + + 800[256]\d{4} + 80021234 + @@ -3513,7 +3725,9 @@ 22212345 - (?:6(?:50|7[12]|8[0-7]|9\d)|7(?:80|9\d))\d{5} + + (?:6(?:50|7[12]|[89]\d)|7(?:80|9\d))\d{5} 65012345 @@ -3619,11 +3833,11 @@ - (?:2(?:0(?:2[0-589]|7[027-9])|1(?:2[5-7]|[3-9]\d))|442\d)\d{4} + (?:2(?:0(?:2[0-589]|7[027-9])|1(?:2[5-7]|[3-689]\d))|442\d)\d{4} 20212345 - (?:6(?:[569]\d)|7(?:[359][0-4]|4[014-7]|6\d|8[1-9]))\d{5} + (?:6(?:[569]\d)|7(?:[3579][0-4]|4[014-7]|6\d|8[1-9]))\d{5} 65012345 @@ -3715,7 +3929,9 @@ 28212345 - 66\d{6} + + 6[26]\d{6} 66123456 @@ -3818,10 +4034,10 @@ happen August 2010, and 7 digit numbers will be phased out by 1 November 2010. --> - $1 $2 + $1 $2 - [2-8]\d{6} + [2-9]\d{6} \d{7} @@ -3831,7 +4047,8 @@ 2012345 - (?:25\d|4(?:2[12389]|9\d)|7\d{2}|87[15-7]|9[13-8]\d)\d{4} + + (?:25\d|4(?:2[12389]|9\d)|7\d{2}|87[15-7]|9[1-8]\d)\d{4} 2512345 @@ -4046,6 +4263,7 @@ + @@ -4075,7 +4293,9 @@ 612012345 - 8(?:1(?:1[0-2]|[23]\d|50)|5\d{2})\d{5} + + 8(?:1(?:1[0-24]|[2-4]\d|50|6[0-2])|5\d{2})\d{5} \d{9} 811012345 @@ -4092,8 +4312,38 @@ - + + + + + $1 $2 $3 $4 + $1 $2 $3 + + + + [029]\d{7} + \d{8} + + + + 2(?:0(?:20|3[1-7]|4[134]|5[14]|6[14578]|7[1-578])|1(?:4[145]|5[14]|6[14-68]|7[169]|88))\d{4} + 20201234 + + + + 9[03467]\d{6} + 93123456 + + + 08\d{6} + 08123456 + + + 09\d{6} + 09123456 + @@ -4101,7 +4351,7 @@ - + @@ -4111,7 +4361,7 @@ pattern="(9)(\d{3})(\d{4})">$1 $2 $3 $1 $2 $3 - $1 $2 $3 $1 $2 $3 @@ -4134,7 +4384,8 @@ 12345678 - (?:70[3-9]|8(?:0[2-9]|12))\d{7}|(?:702[1-9]|819[01])\d{6} + + (?:70[3-9]|8(?:0[2-9]|1[23]))\d{7}|(?:702[1-9]|819[01])\d{6} \d{10} 8021234567 @@ -4353,7 +4604,7 @@ $1 $2 - (?:2[3-6]|5|9[25-9])\d{6}|800\d{5,6} + (?:2[3-6]|5|9[235-9])\d{6}|800\d{5,6} \d{7,9} @@ -4362,7 +4613,9 @@ 23123456 - 9[25-9]\d{6} + + 9[235-9]\d{6} \d{8} 92123456 @@ -4471,7 +4724,7 @@ 21234567 - 9(?:0[5-9]|1[025-9]|2[0-36-9]|3[235-8]|7[349])\d{7} + 9(?:0[5-9]|1[025-9]|2[0-36-9]|3[0235-9]|7[349]|[89]9)\d{7} \d{10} 9051234567 @@ -4529,14 +4782,12 @@ - + - $1 $2 $3 $4 - $1 $2 $3 $4 - $1 $2 $3 + $1 $2 $3 [1-9]\d{8} @@ -4547,7 +4798,7 @@ 123456789 - (?:5[01]|6[069]|7[289]|88)\d{7} + (?:5[013]|6[069]|7[289]|88)\d{7} 512345678 @@ -4663,7 +4914,7 @@ 4123456 - (?:3[0-5]|[5-7]\d)\d{5} + [35-7]\d{6} 3123456 @@ -4787,8 +5038,8 @@ - + @@ -4897,8 +5148,38 @@ - + + + + + $1 $2 + + + [2-8]\d{5} + \d{6} + + + + (?:2(?:1[78]|2[14-69]|3[2-4]|4[1-36-8]|6[167]|[89]\d)|3(?:2[1-6]|4[4-6]|55|6[016]|7\d|8[0-589]|9[0-5])|5(?:5\d|6[0-2])|6(?:0[0-27-9]|1[0-478]|2[145]|3[02-4]|4[124]|6[015]|7\d|8[1-3])|78[0138])\d{3} + 217123 + + + (?:5(?:[1247-9]\d|6[3-9])|7(?:[14679]\d|2[1-9]|8[24-79]))\d{3} + 510123 + + + 8000\d{2} + 800000 + + + 4[1-37]\d{4} + 410123 + @@ -5008,7 +5289,7 @@ $1 $2 $3 $4 - $1 $2 $3 $1 $2 @@ -5022,7 +5303,7 @@ 1123456 - (?:[347][01]|51|64)\d{6} + (?:[37][01]|4[019]|51|64)\d{6} \d{8} 31234567 @@ -5083,8 +5364,29 @@ + + nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)"> + + + $1 $2 + + + [2-578]\d{7} + \d{6,8} + + + [235]2[2-4][2-9]\d{4} + 22221234 + + + + (?:25|3[03]|44|5[056]|7[6-8]|88)[1-9]\d{5} + 25123456 + @@ -5109,7 +5411,9 @@ 301012345 - 7(?:0[1256]0|6(?:1[23]|2[89]|3[3489]|4[6-9]|5[1-389]|6[6-9]|7[45]|8[3-8])|7(?:1[014-8]|2[0-7]|3[0-35-8]|4[0-6]|[56]\d|7[0-389]|[89][01]))\d{5} + + 7(?:0[1256]0|6(?:1[23]|2[89]|3[3489]|4[6-9]|5[1-389]|6[6-9]|7[45]|8[3-8])|7(?:1[014-8]|2[0-7]|3[0-35-8]|4[0-6]|[56]\d|7[0-589]|8[01]|9[0-6]))\d{5} 701012345 @@ -5119,7 +5423,38 @@ + + + + + $1 $2 + + $1 $2 + + + [13-59]\d{6,7} + \d{7,8} + + + (?:5[57-9]|[134]\d)\d{5} + \d{7} + + 5522010 + + + (?:9[01]|15)\d{6} + \d{8} + 90792024 + @@ -5171,7 +5506,10 @@ 112345678 - 9(?:3[23]|4[47]|55|66|88|99)\d{6} + + 9(?:3[23]|4[457]|55|6[67]|88|9[19])\d{6} \d{9} 944567890 @@ -5249,21 +5587,22 @@ internationalPrefix="00|16"> $1 $2 $3 + pattern="(\d{2})(\d{2})(\d{2})(\d{2})">$1 $2 $3 $4 - [2369]\d{6} - \d{7} + [2679]\d{7} + \d{8} - 2(?:5[0-4]|6[89])\d{4} - 2511234 + 22(?:[3789]0|5[0-5]|6[89])\d{4} + 22501234 - - (?:3[0-7]|6[27]|9\d)\d{5} - 6201234 + + (?:6(?:3[0-7]|6\d)|77\d|9(?:5[0-4]|9\d))\d{5} + 63012345 @@ -5318,7 +5657,9 @@ 21234567 - 8[13-9]\d{7} + + 8\d{8} \d{9} 812345678 @@ -5349,9 +5690,9 @@ pattern="([349]\d{2})(\d{2})(\d{4})">$1 $2 $3 $1 $2 $3 $1 $2 $3 - $1 $2 $3 - $1 $2 $3 @@ -5363,7 +5704,9 @@ 372123456 - 9[1-35-9]\d{7} + + 9[0-35-9]\d{7} \d{9} 917123456 @@ -5381,18 +5724,27 @@ + nationalPrefix="8" nationalPrefixFormattingRule="$NP $FG"> - $1 $2 $3 $4 + $1 $2 $3 $4 - (?:12\d|243|[3-5]22)\d{5} + [1-6]\d{7} \d{8} - 12345678 + + (?:12\d|243|[3-5]22)\d{5} + 12345678 + + + + 6[6-8]\d{6} + 66123456 + @@ -5565,7 +5917,7 @@ is useful but not error-free. Have used local yellow pages guidelines, Google searches and regression tests to reverse-engineer these rules. --> - $1 $2 $3 \d{7,9} - (?:6[125679]|7[1-69])\d{7} + + (?:6[125679]|7[0-69])\d{7} 612345678 - 9[0-37-9]\d{7} + + 9[0-57-9]\d{7} 912345678 @@ -5824,7 +6180,9 @@ 2101234567 - (?:9[0-8]|1(?:2\d|6[46-9]|99))\d{7} + + (?:9[0-8]|1(?:2\d|6[3-9]|99))\d{7} \d{9,10} 912345678 @@ -5990,10 +6348,13 @@ - $1 $2 + $1 $2 + $1 $2 $3 - [29]\d{8} + [289]\d{8} \d{9} @@ -6001,9 +6362,16 @@ 211234567 - 9(?:55|66|7[7-9])\d{6} + + 9(?:55|6[4-9]|7[4-9])\d{6} 955123456 + + 800\d{6} + 800123456 + diff --git a/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto b/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto index 2cad06486..27aeaa299 100644 Binary files a/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto and b/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto differ diff --git a/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml b/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml index 21d2da387..524507bbf 100644 --- a/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml +++ b/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml @@ -16,7 +16,8 @@ MetaData on Phone Number Plan and formatting rules. This file is used solely for the purpose of unittesting, so data in this file is not - necessarily consistent with that of PhoneNumberMetaData.xml + necessarily consistent with that of + ../src/PhoneNumberMetaData.xml --> @@ -233,6 +234,52 @@ + + + + + + + + + + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3-$4 + $1-$2-$3 + $1-$2-$3 + $1-$2 + $1-$2 + $1-$2 + $1-$2 + + + [1-79]\d{3,9}|8\d{8} + \d{4,10} + + + 0) { - numberDesc.setPossibleNumberPattern(possiblePattern. - item(0).getFirstChild().getNodeValue()); + numberDesc.setPossibleNumberPattern( + validateRE(possiblePattern.item(0).getFirstChild().getNodeValue())); } NodeList validPattern = element.getElementsByTagName("nationalNumberPattern"); if (validPattern.getLength() > 0) { - numberDesc.setNationalNumberPattern(validPattern. - item(0).getFirstChild().getNodeValue()); + numberDesc.setNationalNumberPattern( + validateRE(validPattern.item(0).getFirstChild().getNodeValue())); } if (!liteBuild) { diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index dc5fae4d0..bac6434e4 100644 --- a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -161,6 +161,7 @@ public class PhoneNumberUtil { new ImmutableSet.Builder() .add(39) // Italy .add(225) // C™te d'Ivoire + .add(227) // Niger .add(228) // Togo .add(240) // Equatorial Guinea .add(241) // Gabon @@ -562,7 +563,7 @@ public class PhoneNumberUtil { * supplied is used only for the resultant log message. */ private boolean isValidRegionCode(String regionCode, int countryCode, String number) { - if (regionCode == null || regionCode.equals("ZZ")) { + if (regionCode == null || regionCode.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.WARNING, "Number " + number + "has invalid or missing country code (" + countryCode + ")"); return false; @@ -674,11 +675,12 @@ public class PhoneNumberUtil { */ public String formatOutOfCountryCallingNumber(PhoneNumber number, String countryCallingFrom) { - if (countryCallingFrom == null || countryCallingFrom.equals("ZZ")) { + if (countryCallingFrom == null || countryCallingFrom.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.WARNING, "Trying to format number from invalid region. International formatting applied."); return format(number, PhoneNumberFormat.INTERNATIONAL); } + countryCallingFrom = countryCallingFrom.toUpperCase(); int countryCode = number.getCountryCode(); if (countryCode == NANPA_COUNTRY_CODE && isNANPACountry(countryCallingFrom)) { // For NANPA countries, return the national format for these countries but prefix it with the @@ -837,6 +839,7 @@ public class PhoneNumberUtil { * does not contain such information. */ public PhoneNumber getExampleNumber(String regionCode) { + regionCode = regionCode.toUpperCase(); return getExampleNumberForType(regionCode, PhoneNumberType.FIXED_LINE); } @@ -850,6 +853,7 @@ public class PhoneNumberUtil { * does not contain such information. */ public PhoneNumber getExampleNumberForType(String regionCode, PhoneNumberType type) { + regionCode = regionCode.toUpperCase(); PhoneNumberDesc desc = getNumberDescByType(getMetadataForRegion(regionCode), type); try { if (desc.hasExampleNumber()) { @@ -1021,6 +1025,7 @@ public class PhoneNumberUtil { * @return a boolean that indicates whether the number is of a valid pattern */ public boolean isValidNumberForRegion(PhoneNumber number, String regionCode) { + regionCode = regionCode.toUpperCase(); if (number.getCountryCode() != getCountryCodeForRegion(regionCode)) { return false; } @@ -1098,11 +1103,11 @@ public class PhoneNumberUtil { * @return the country calling code for the country/region denoted by regionCode */ public int getCountryCodeForRegion(String regionCode) { - if (regionCode == null || regionCode.equals("ZZ")) { + if (regionCode == null || regionCode.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.SEVERE, "Invalid or missing country code provided."); return 0; } - PhoneMetadata metadata = getMetadataForRegion(regionCode); + PhoneMetadata metadata = getMetadataForRegion(regionCode.toUpperCase()); if (metadata == null) { LOGGER.log(Level.SEVERE, "Unsupported country code provided."); return 0; @@ -1117,6 +1122,7 @@ public class PhoneNumberUtil { * @return true if regionCode is one of the countries under NANPA */ public boolean isNANPACountry(String regionCode) { + regionCode = regionCode.toUpperCase(); return nanpaCountries.contains(regionCode); } @@ -1202,6 +1208,7 @@ public class PhoneNumberUtil { * @return true if the number is possible */ public boolean isPossibleNumber(String number, String countryDialingFrom) { + countryDialingFrom = countryDialingFrom.toUpperCase(); try { return isPossibleNumber(parse(number, countryDialingFrom)); } catch (NumberParseException e) { @@ -1225,6 +1232,7 @@ public class PhoneNumberUtil { * specific country "as you type" */ public AsYouTypeFormatter getAsYouTypeFormatter(String regionCode) { + regionCode = regionCode.toUpperCase(); return new AsYouTypeFormatter(regionCode); } @@ -1472,11 +1480,11 @@ public class PhoneNumberUtil { */ public PhoneNumber parse(String numberToParse, String defaultCountry) throws NumberParseException { - if (defaultCountry == null || defaultCountry.equals("ZZ")) { + if (defaultCountry == null || defaultCountry.equalsIgnoreCase("ZZ")) { throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, "No default country was supplied."); } - return parseHelper(numberToParse, defaultCountry, false); + return parseHelper(numberToParse, defaultCountry.toUpperCase(), false); } /** @@ -1496,11 +1504,11 @@ public class PhoneNumberUtil { */ public PhoneNumber parseAndKeepRawInput(String numberToParse, String defaultCountry) throws NumberParseException { - if (defaultCountry == null || defaultCountry.equals("ZZ")) { + if (defaultCountry == null || defaultCountry.equalsIgnoreCase("ZZ")) { throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, "No default country was supplied."); } - return parseHelper(numberToParse, defaultCountry, true); + return parseHelper(numberToParse, defaultCountry.toUpperCase(), true); } /** @@ -1588,11 +1596,6 @@ public class PhoneNumberUtil { countryMetadata.getNationalPrefixTransformRule(), validNumberPattern); } - phoneNumber.setCountryCode(countryCode); - if (isLeadingZeroCountry(countryCode) && - normalizedNationalNumber.charAt(0) == '0') { - phoneNumber.setItalianLeadingZero(true); - } int lengthOfNationalNumber = normalizedNationalNumber.length(); if (lengthOfNationalNumber < MIN_LENGTH_FOR_NSN) { throw new NumberParseException(NumberParseException.ErrorType.TOO_SHORT_NSN, @@ -1604,6 +1607,11 @@ public class PhoneNumberUtil { "The string supplied is too long to be a " + "phone number."); } + phoneNumber.setCountryCode(countryCode); + if (isLeadingZeroCountry(countryCode) && + normalizedNationalNumber.charAt(0) == '0') { + phoneNumber.setItalianLeadingZero(true); + } phoneNumber.setNationalNumber(Long.parseLong(normalizedNationalNumber.toString())); return phoneNumber.build(); } diff --git a/java/src/com/google/i18n/phonenumbers/phonemetadata.proto b/java/src/com/google/i18n/phonenumbers/phonemetadata.proto index 3e744e3c1..e42bca156 100644 --- a/java/src/com/google/i18n/phonenumbers/phonemetadata.proto +++ b/java/src/com/google/i18n/phonenumbers/phonemetadata.proto @@ -20,8 +20,11 @@ syntax = "proto2"; +option cc_api_version = 1; +option java_api_version = 1; +option py_api_version = 1; + option java_package = "com.google.i18n.phonenumbers"; -option optimize_for = LITE_RUNTIME; package i18n.phonenumbers; message NumberFormat { @@ -51,9 +54,18 @@ message NumberFormat { // This field specifies how the national prefix ($NP) together with the first // group ($FG) in the national significant number should be formatted in // the NATIONAL format when a national prefix exists for a certain country. - // When present, it overrides the national_prefix_formatting_rule specified - // in PhoneNumberDesc. See the comment in PhoneNumberDesc for more information - // on how this rule is specified. + // For example, when this field contains "($NP$FG)", a number from Beijing, + // China (whose $NP = 0), which would by default be formatted without + // national prefix as 10 1234 5678 in NATIONAL format, will instead be + // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field + // would contain "($NP)$FG". Note $FG should always be present in this field, + // but $NP can be omitted. For example, having "$FG" could indicate the + // number should be formatted in NATIONAL format without the national prefix. + // This is commonly used to override the rule from generalDesc. + // + // When this field is missing, a number will be formatted without national + // prefix in NATIONAL format. This field does not affect how a number + // is formatted in other formats, such as INTERNATIONAL. optional string national_prefix_formatting_rule = 4; } @@ -184,24 +196,7 @@ message PhoneMetadata { // 15 (inserted after the area code of 343) is used. repeated NumberFormat intl_number_format = 20; - // This field specifies how the national prefix ($NP) together with the first - // group ($FG) in the national significant number should be formatted in - // the NATIONAL format when a national prefix exists for a certain country. - // For example, when this field contains "($NP$FG)", a number from Beijing, - // China (whose $NP = 0), which would by default be formatted without - // national prefix as 10 1234 5678 in NATIONAL format, will instead be - // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field - // would contain "($NP)$FG". Note $FG should always be present in this field, - // but $NP can be omitted. For example, having "$FG" could indicate the - // number should be formatted in NATIONAL format without the national prefix. - // This is commonly used to override the rule from generalDesc. - // - // When this field is missing, a number will be formatted without national - // prefix in NATIONAL format. This field does not affect how a number - // is formatted in other formats, such as INTERNATIONAL. - // - // This field applies to all numberFormats unless overridden by the - // national_prefix_formatting_rule in a specific numberFormat. + // Deprecated. optional string national_prefix_formatting_rule = 21; } diff --git a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java index d464cd265..f8758bc00 100644 --- a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java +++ b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java @@ -196,7 +196,7 @@ public class AsYouTypeFormatterTest extends TestCase { } public void testAsYouTypeFormatterGBTollFree() { - AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("GB"); + AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("gb"); assertEquals("0", formatter.inputDigit('0')); assertEquals("08", formatter.inputDigit('8')); assertEquals("080", formatter.inputDigit('0')); @@ -282,4 +282,94 @@ public class AsYouTypeFormatterTest extends TestCase { assertEquals("+54 9 11 2312 123\u2008", formatter.inputDigit('3')); assertEquals("+54 9 11 2312 1234", formatter.inputDigit('4')); } + + public void testAsYouTypeFormatterKR() { + // +82 51 234 5678 + AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("KR"); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+825", formatter.inputDigit('5')); + assertEquals("+8251", formatter.inputDigit('1')); + assertEquals("+82 512", formatter.inputDigit('2')); + assertEquals("+82 51-23\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('3')); + assertEquals("+82 51-234-\u2008\u2008\u2008\u2008", formatter.inputDigit('4')); + assertEquals("+82 51-234-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 51-234-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 51-234-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 51-234-5678", formatter.inputDigit('8')); + + // +82 2 531 5678 + formatter.clear(); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+822", formatter.inputDigit('2')); + assertEquals("+8225", formatter.inputDigit('5')); + assertEquals("+82 253", formatter.inputDigit('3')); + assertEquals("+82 2-531-\u2008\u2008\u2008\u2008", formatter.inputDigit('1')); + assertEquals("+82 2-531-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-531-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-531-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 2-531-5678", formatter.inputDigit('8')); + + // +82 2 3665 5678 + formatter.clear(); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+822", formatter.inputDigit('2')); + assertEquals("+8223", formatter.inputDigit('3')); + assertEquals("+82 236", formatter.inputDigit('6')); + assertEquals("+82 2-366\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-3665-\u2008\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-3665-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-3665-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-3665-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 2-3665-5678", formatter.inputDigit('8')); + + // 02-114 : This is too short to format. Checking that there are no side-effects. + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("02", formatter.inputDigit('2')); + assertEquals("021", formatter.inputDigit('1')); + assertEquals("0211", formatter.inputDigit('1')); + assertEquals("02114", formatter.inputDigit('4')); + + // 02-1300 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("02", formatter.inputDigit('2')); + assertEquals("021", formatter.inputDigit('1')); + assertEquals("0213", formatter.inputDigit('3')); + assertEquals("02130", formatter.inputDigit('0')); + assertEquals("02-1300", formatter.inputDigit('0')); + + // 011-456-7890 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("01", formatter.inputDigit('1')); + assertEquals("011", formatter.inputDigit('1')); + assertEquals("0114", formatter.inputDigit('4')); + assertEquals("01145", formatter.inputDigit('5')); + assertEquals("011-456-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("011-456-7\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-456-78\u2008\u2008", formatter.inputDigit('8')); + assertEquals("011-456-789\u2008", formatter.inputDigit('9')); + assertEquals("011-456-7890", formatter.inputDigit('0')); + + // 011-9876-7890 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("01", formatter.inputDigit('1')); + assertEquals("011", formatter.inputDigit('1')); + assertEquals("0119", formatter.inputDigit('9')); + assertEquals("01198", formatter.inputDigit('8')); + assertEquals("011-987\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-9876-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("011-9876-7\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-9876-78\u2008\u2008", formatter.inputDigit('8')); + assertEquals("011-9876-789\u2008", formatter.inputDigit('9')); + assertEquals("011-9876-7890", formatter.inputDigit('0')); + } } diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 746a3ed94..43ded0fa3 100644 --- a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -123,6 +123,7 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber deNumber = PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(30123456).build(); assertEquals(deNumber, phoneUtil.getExampleNumber("DE")); + assertEquals(deNumber, phoneUtil.getExampleNumber("de")); assertEquals(deNumber, phoneUtil.getExampleNumberForType("DE", @@ -415,6 +416,8 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AU")); assertEquals("011 15 8765-4321 ext. 1234", phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AR")); + assertEquals("011 15 8765-4321 ext. 1234", + phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "ar")); } public void testFormatOutOfCountryWithPreferredIntlPrefix() { @@ -687,6 +690,7 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2423232345L).build(); assertTrue(phoneUtil.isValidNumber(bsNumber1)); assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "BS")); + assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "bs")); assertFalse(phoneUtil.isValidNumberForRegion(bsNumber1, "US")); PhoneNumber bsNumber2 = PhoneNumber.newBuilder(bsNumber1).setNationalNumber(2421232345L).build(); @@ -739,6 +743,7 @@ public class PhoneNumberUtilTest extends TestCase { public void testGetCountryCodeForRegion() { assertEquals(1, phoneUtil.getCountryCodeForRegion("US")); assertEquals(64, phoneUtil.getCountryCodeForRegion("NZ")); + assertEquals(64, phoneUtil.getCountryCodeForRegion("nz")); assertEquals(0, phoneUtil.getCountryCodeForRegion(null)); assertEquals(0, phoneUtil.getCountryCodeForRegion("ZZ")); // CS is already deprecated so the library doesn't support it. @@ -748,6 +753,7 @@ public class PhoneNumberUtilTest extends TestCase { public void testIsNANPACountry() { assertTrue(phoneUtil.isNANPACountry("US")); assertTrue(phoneUtil.isNANPACountry("BS")); + assertTrue(phoneUtil.isNANPACountry("bs")); } public void testIsPossibleNumber() { @@ -771,6 +777,7 @@ public class PhoneNumberUtilTest extends TestCase { assertTrue(phoneUtil.isPossibleNumber("(020) 7031 3000", "GB")); assertTrue(phoneUtil.isPossibleNumber("7031 3000", "GB")); assertTrue(phoneUtil.isPossibleNumber("3331 6005", "NZ")); + assertTrue(phoneUtil.isPossibleNumber("3331 6005", "nz")); } public void testIsPossibleNumberWithReason() { @@ -1032,22 +1039,11 @@ public class PhoneNumberUtilTest extends TestCase { // National prefix attached. assertEquals(nzNumber, phoneUtil.parse("033316005", "NZ")); + assertEquals(nzNumber, phoneUtil.parse("033316005", "nz")); assertEquals(nzNumber, phoneUtil.parse("33316005", "NZ")); // National prefix attached and some formatting present. assertEquals(nzNumber, phoneUtil.parse("03-331 6005", "NZ")); assertEquals(nzNumber, phoneUtil.parse("03 331 6005", "NZ")); - // Test case with alpha characters. - PhoneNumber tollfreeNumber = - PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(800332005L).build(); - assertEquals(tollfreeNumber, phoneUtil.parse("0800 DDA 005", "NZ")); - PhoneNumber premiumNumber = - PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(9003326005L).build(); - assertEquals(premiumNumber, phoneUtil.parse("0900 DDA 6005", "NZ")); - // Not enough alpha characters for them to be considered intentional, so they are stripped. - assertEquals(premiumNumber, phoneUtil.parse("0900 332 6005a", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 332 600a5", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 332 600A5", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 a332 600A5", "NZ")); // Testing international prefixes. // Should strip country code. @@ -1057,11 +1053,38 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(nzNumber, phoneUtil.parse("01164 3 331 6005", "US")); assertEquals(nzNumber, phoneUtil.parse("+64 3 331 6005", "US")); - // Test for http://b/issue?id=2247493 PhoneNumber nzNumber2 = PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(64123456L).build(); assertEquals(nzNumber2, phoneUtil.parse("64(0)64123456", "NZ")); + // Check that using a "/" is fine in a phone number. + PhoneNumber deNumber = + PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(12345678L).build(); + assertEquals(deNumber, phoneUtil.parse("123/45678", "DE")); + // Check it doesn't use the '1' as a country code when parsing if the phone number was already + // possible. + PhoneNumber usNumber = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(1234567890L).build(); + assertEquals(usNumber, phoneUtil.parse("123-456-7890", "US")); + + } + + public void testParseNumberWithAlphaCharacters() throws Exception { + // Test case with alpha characters. + PhoneNumber tollfreeNumber = + PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(800332005L).build(); + assertEquals(tollfreeNumber, phoneUtil.parse("0800 DDA 005", "NZ")); + PhoneNumber premiumNumber = + PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(9003326005L).build(); + assertEquals(premiumNumber, phoneUtil.parse("0900 DDA 6005", "NZ")); + // Not enough alpha characters for them to be considered intentional, so they are stripped. + assertEquals(premiumNumber, phoneUtil.parse("0900 332 6005a", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 332 600a5", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 332 600A5", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 a332 600A5", "NZ")); + } + + public void testParseWithInternationalPrefixes() throws Exception { PhoneNumber usNumber = PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6503336000L).build(); assertEquals(usNumber, phoneUtil.parse("+1 (650) 333-6000", "NZ")); @@ -1075,12 +1098,9 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(usNumber, phoneUtil.parse("0191-650-333-6000", "SG")); // Calling the US number from Poland assertEquals(usNumber, phoneUtil.parse("0~01-650-333-6000", "PL")); - // Check it doesn't use the '1' as a country code when parsing if the phone number was already - // possible. - PhoneNumber usNumber2 = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(1234567890L).build(); - assertEquals(usNumber2, phoneUtil.parse("123-456-7890", "US")); + } + public void testParseWithLeadingZero() throws Exception { PhoneNumber itNumber = PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L) .setItalianLeadingZero(true).build(); @@ -1090,12 +1110,9 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber itNumber2 = PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(312345678L).build(); assertEquals(itNumber2, phoneUtil.parse("312 345 678", "IT")); + } - // Check that using a "/" is fine in a phone number. - PhoneNumber deNumber = - PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(12345678L).build(); - assertEquals(deNumber, phoneUtil.parse("123/45678", "DE")); - + public void testParseNationalNumberArgentina() throws Exception { // Test parsing mobile numbers of Argentina. PhoneNumber arNumber = PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(93435551212L).build(); @@ -1122,7 +1139,9 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(2312340000L).build(); assertEquals(arNumber5, phoneUtil.parse("+54 23 1234 0000", "AR")); assertEquals(arNumber5, phoneUtil.parse("023 1234 0000", "AR")); + } + public void testParseWithXInNumber() throws Exception { // Test that having an 'x' in the phone number at the start is ok and that it just gets removed. PhoneNumber arNumber6 = PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(123456789L).build(); @@ -1137,7 +1156,9 @@ public class PhoneNumberUtilTest extends TestCase { // to 7 digits. This assumption is okay for now as all the countries where a carrier selection // code is written in the form of xx have a national significant number of length larger than 7. assertEquals(arFromUs, phoneUtil.parse("011xx5481429712", "US")); + } + public void testParseNumbersMexico() throws Exception { // Test parsing fixed-line numbers of Mexico. PhoneNumber mxNumber = PhoneNumber.newBuilder().setCountryCode(52).setNationalNumber(4499780001L).build(); @@ -1151,24 +1172,6 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(mxNumber2, phoneUtil.parse("+52 1 33 1234-5678", "MX")); assertEquals(mxNumber2, phoneUtil.parse("044 (33) 1234-5678", "MX")); assertEquals(mxNumber2, phoneUtil.parse("045 33 1234-5678", "MX")); - - // Test that if a number has two extensions specified, we ignore the second. - PhoneNumber usWithTwoExtensionsNumber = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2121231234L) - .setExtension("508").build(); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/x1234", - "US")); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/ x1234", - "US")); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508\\x1234", - "US")); - - // Test parsing numbers in the form (645) 123-1234-910# works, where the last 3 digits before - // the # are an extension. - PhoneNumber usWithExtension = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6451231234L) - .setExtension("910").build(); - assertEquals(usWithExtension, phoneUtil.parse("+1 (645) 123 1234-910#", "US")); } public void testFailedParseOnInvalidNumbers() { @@ -1317,6 +1320,24 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.parse("(800) 901-3355 ,extension 7246433", "US")); assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 , 7246433", "US")); assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 ext: 7246433", "US")); + + // Test that if a number has two extensions specified, we ignore the second. + PhoneNumber usWithTwoExtensionsNumber = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2121231234L) + .setExtension("508").build(); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/x1234", + "US")); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/ x1234", + "US")); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508\\x1234", + "US")); + + // Test parsing numbers in the form (645) 123-1234-910# works, where the last 3 digits before + // the # are an extension. + PhoneNumber usWithExtension2 = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6451231234L) + .setExtension("910").build(); + assertEquals(usWithExtension2, phoneUtil.parse("+1 (645) 123 1234-910#", "US")); } public void testParseAndKeepRaw() throws Exception { @@ -1334,7 +1355,7 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals("+376 12345", phoneUtil.format(adNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL)); assertEquals("+37612345", phoneUtil.format(adNumber, - PhoneNumberUtil.PhoneNumberFormat.E164)); + PhoneNumberUtil.PhoneNumberFormat.E164)); assertEquals("12345", phoneUtil.format(adNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL)); assertEquals(PhoneNumberUtil.PhoneNumberType.UNKNOWN,