phony 1.9.0 → 2.19.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +64 -112
  3. data/lib/phony/config.rb +91 -0
  4. data/lib/phony/countries/argentina.rb +355 -0
  5. data/lib/phony/countries/austria.rb +56 -22
  6. data/lib/phony/countries/bangladesh.rb +57 -0
  7. data/lib/phony/countries/belarus.rb +133 -0
  8. data/lib/phony/countries/brazil.rb +101 -95
  9. data/lib/phony/countries/cambodia.rb +131 -0
  10. data/lib/phony/countries/china.rb +13 -6
  11. data/lib/phony/countries/croatia.rb +23 -0
  12. data/lib/phony/countries/georgia.rb +94 -0
  13. data/lib/phony/countries/germany.rb +66 -42
  14. data/lib/phony/countries/guinea.rb +46 -0
  15. data/lib/phony/countries/india.rb +50 -0
  16. data/lib/phony/countries/indonesia.rb +55 -0
  17. data/lib/phony/countries/ireland.rb +35 -28
  18. data/lib/phony/countries/italy.rb +272 -166
  19. data/lib/phony/countries/japan.rb +468 -0
  20. data/lib/phony/countries/kyrgyzstan.rb +120 -0
  21. data/lib/phony/countries/latvia.rb +43 -0
  22. data/lib/phony/countries/libya.rb +116 -0
  23. data/lib/phony/countries/malaysia.rb +31 -7
  24. data/lib/phony/countries/moldova.rb +53 -0
  25. data/lib/phony/countries/montenegro.rb +30 -0
  26. data/lib/phony/countries/myanmar.rb +55 -0
  27. data/lib/phony/countries/namibia.rb +37 -0
  28. data/lib/phony/countries/nepal.rb +73 -0
  29. data/lib/phony/countries/netherlands.rb +17 -5
  30. data/lib/phony/countries/pakistan.rb +121 -0
  31. data/lib/phony/countries/paraguay.rb +147 -0
  32. data/lib/phony/countries/{russia_kazakhstan_abhasia_south_osetia.rb → russia_kazakhstan_abkhasia_south_ossetia.rb} +35 -24
  33. data/lib/phony/countries/saudi_arabia.rb +40 -0
  34. data/lib/phony/countries/serbia.rb +47 -0
  35. data/lib/phony/countries/somalia.rb +26 -0
  36. data/lib/phony/countries/south_korea.rb +19 -10
  37. data/lib/phony/countries/sweden.rb +58 -38
  38. data/lib/phony/countries/taiwan.rb +28 -0
  39. data/lib/phony/countries/tajikistan.rb +79 -0
  40. data/lib/phony/countries/turkmenistan.rb +76 -0
  41. data/lib/phony/countries/ukraine.rb +630 -0
  42. data/lib/phony/countries/united_kingdom.rb +639 -44
  43. data/lib/phony/countries/uruguay.rb +53 -0
  44. data/lib/phony/countries/vietnam.rb +133 -0
  45. data/lib/phony/countries/zimbabwe.rb +39 -0
  46. data/lib/phony/countries.rb +901 -301
  47. data/lib/phony/country.rb +177 -20
  48. data/lib/phony/country_codes.rb +119 -101
  49. data/lib/phony/dsl.rb +113 -68
  50. data/lib/phony/local_splitters/fixed.rb +25 -1
  51. data/lib/phony/local_splitters/regex.rb +16 -2
  52. data/lib/phony/national_code.rb +7 -7
  53. data/lib/phony/national_splitters/default.rb +35 -3
  54. data/lib/phony/national_splitters/dsl.rb +12 -7
  55. data/lib/phony/national_splitters/fixed.rb +7 -1
  56. data/lib/phony/national_splitters/none.rb +7 -3
  57. data/lib/phony/national_splitters/regex.rb +6 -0
  58. data/lib/phony/national_splitters/variable.rb +13 -9
  59. data/lib/phony/trunk_code.rb +57 -0
  60. data/lib/phony/vanity.rb +3 -3
  61. data/lib/phony.rb +239 -55
  62. data/spec/functional/config_spec.rb +44 -0
  63. data/spec/functional/plausibility_spec.rb +656 -0
  64. data/spec/lib/phony/countries_spec.rb +1207 -119
  65. data/spec/lib/phony/country_codes_spec.rb +99 -81
  66. data/spec/lib/phony/country_spec.rb +54 -14
  67. data/spec/lib/phony/dsl_spec.rb +2 -2
  68. data/spec/lib/phony/local_splitters/fixed_spec.rb +4 -4
  69. data/spec/lib/phony/local_splitters/regex_spec.rb +50 -2
  70. data/spec/lib/phony/national_code_spec.rb +34 -34
  71. data/spec/lib/phony/national_splitters/default_spec.rb +34 -0
  72. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -6
  73. data/spec/lib/phony/national_splitters/none_spec.rb +13 -3
  74. data/spec/lib/phony/national_splitters/regex_spec.rb +1 -1
  75. data/spec/lib/phony/national_splitters/variable_spec.rb +11 -5
  76. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  77. data/spec/lib/phony/vanity_spec.rb +15 -19
  78. data/spec/lib/phony_spec.rb +59 -277
  79. metadata +67 -34
  80. data/lib/phony/validator.rb +0 -26
  81. data/lib/phony/validators.rb +0 -88
  82. data/spec/lib/phony/validations_spec.rb +0 -109
@@ -1,3 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
1
4
  # All countries, ordered by country code.
2
5
  #
3
6
  # Definitions are in the format:
@@ -6,99 +9,156 @@
6
9
  # As soon as a NDC matches, it goes on to the National part. Then breaks off.
7
10
  # If the NDC does not match, it go on to the next (|, or "or") NDC.
8
11
  #
12
+ # For the pre-ndc part, there's:
13
+ # * trunk: If the country has a trunk code (options normalize/split – remove trunk on these method, default false).
14
+ #
9
15
  # Available matching/splitting methods:
10
16
  # * none: Does not have a national destination code, e.g. Denmark, Iceland.
11
17
  # * one_of: Matches one of the following numbers. Splits if it does.
12
18
  # * match: Try to match the regex, and if it matches, splits it off.
13
- # * fixed: Always splits off a fixed length ndc. (Always use last in a | chain as a catchall) Offers a "zero" formatting option (default true).
19
+ # * fixed: Always splits off a fixed length ndc. (Always use last in a | chain as a catchall)
14
20
  #
15
21
  # For the national number part, there are two:
16
22
  # * split: Use this number group splitting.
17
23
  # * matched_split: Give a hash of regex => format array, with a :fallback => format option.
18
24
  # (See Norway how it looks.)
19
25
  #
20
- # The third parameter to country are validations.
21
- # Currently, there is one method available:
22
- # * invalid_ndcs: Give a regexp or string to describe invalid ndc(s).
23
- #
24
26
  # Note: The ones that are commented are defined in their special files.
25
27
  #
28
+ # @example Switzerland (simplified)
29
+ # country('41', fixed(2) >> local([3,2,2]))
30
+ #
31
+ # @example Germany. Too big, we use a separate file
32
+ # Phony.define do
33
+ # country '49', match(...) >> split([...]) ||
34
+ # one_of([...], :max_length => 5) >> split([...])
35
+ # end
36
+ #
37
+ # @example Denmark
38
+ # country('45', none >> split([2,2,2,2]))
39
+ #
40
+ # @example Hungary
41
+ # country('36',
42
+ # match(/^104|105|107|112/) >> split([3,3]) ||
43
+ # one_of([1], :max_length => 2) >> split([3,4])
44
+ # )
45
+ #
26
46
  Phony.define do
27
47
 
28
48
  # Reserved.
29
49
  #
30
- country '0', fixed(1) >> split(10) # Reserved.
50
+ reserved '0'
31
51
 
32
52
  # USA, Canada, etc.
33
53
  #
34
54
  country '1',
35
- fixed(3, :zero => false) >> split(3,4),
36
- invalid_ndcs('911') # /911/ would also work.
37
-
38
- # Kazakhstan (Republic of) & Russian Federation.
55
+ # The US has a delimiter between NDC and local number.
56
+ trunk('1%s', normalize: true, format: false) | # http://en.wikipedia.org/wiki/Trunk_prefix
57
+ fixed(3) >> split(3,4),
58
+ :invalid_ndcs => /[0-1]\d{2}|[3-9]11/,
59
+ :parentheses => true,
60
+ :local_space => :-
61
+
62
+ # Kazakhstan (Republic of) & Russsian Federation.
39
63
  # also Abhasia and South Osetia autonomous regions / recognized by some states as independent countries
40
64
  #country '7', fixed(3) >> split(3,2,2)
41
65
  # see special file
42
66
 
43
67
  # Egypt.
44
68
  #
45
- country '20', one_of('800') >> split(7) | # Egypt
46
- one_of('2', '3') >> split(8) | # Cairo/Giza, Alexandria
47
- fixed(2) >> split(8)
48
- # :mobile? => /^1[01246-9]\d+$/, :service? => /^800\d+$/
69
+ country '20', one_of('800') >> split(7..7) | # Egypt toll free
70
+ one_of('3') >> split(7..7) | # Alexandria
71
+ one_of('2') >> split(8..8) | # Cairo/Giza
72
+ one_of('10', '11', '12', '15') >> split(8..8) | # the 4 mobile operators
73
+ fixed(2) >> split(7..7) # all the other 24 provinces
49
74
 
50
75
  # South Africa.
51
76
  #
52
77
  country '27', fixed(2) >> split(3,4)
53
78
 
54
- # Greece.
55
- #
56
- country '30', match(/^(2[3-8]?1|69[0345789]|800)\d+$/) >> split(8) | # Geo/Mobile
57
- fixed(4) >> split(6) # 3-digit NDCs
79
+ # Greece. http://www.numberingplans.com/?page=dialling&sub=areacodes
80
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GR
81
+ country '30',
82
+ trunk('0') |
83
+ one_of(%w(231 241 251 261 271 281)) >> split(3,4) |
84
+ one_of('800') >> split(3,4) | # freephone
85
+ one_of(%w(801 807)) >> split(3,4) | # shared cost, premium rate
86
+ one_of('896') >> split(3,4) | # ISP
87
+ one_of(%w(901 909)) >> split(3,4) | # premium rate
88
+ one_of(%w(21 22 23 24 25 26 27 28)) >> split(4,4) |
89
+ one_of('50') >> split(4,4) | # VPN
90
+ match(/^(69\d)\d+$/) >> split(3,4) | # mobile, pager
91
+ one_of('70') >> split(4,4) | # universal access
92
+ fixed(4) >> split(6) # 3-digit NDCs
58
93
 
59
94
  # country '31' # Netherlands, see special file.
60
95
 
61
96
  # Belgium.
62
97
  #
63
- country '32', match(/^(70|800|90\d)\d+$/) >> split(3,3) | # Service
64
- match(/^(4[789]\d)\d{6}$/) >> split(6) | # Mobile
65
- one_of('2','3','4','9') >> split(3,5) | # Short NDCs
66
- fixed(2) >> split(3,5) # 2-digit NDCs
98
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
99
+ # https://www.bipt.be/operators/publication/national-numbering-plan
100
+ #
101
+ country '32', trunk('0') |
102
+ match(/^(7[08])\d+$/) >> split(3,3) | # Premium and national rate Services
103
+ match(/^(800|90\d)\d+$/) >> split(2,3) | # Toll free service and premium numbers
104
+ match(/^(46[056789])\d{6}$/) >> split(2,2,2) | # Mobile (Lycamobile, Telenet, Join Experience, Proximus 0460)
105
+ match(/^(4[789]\d)\d{6}$/) >> split(2,2,2) | # Mobile
106
+ match(/^(45[56])\d{6}$/) >> split(2,2,2) | # Mobile Vikings and Voo
107
+ one_of('2','3','4','9') >> split(3,2,2) | # Short NDCs
108
+ fixed(2) >> split(2,2,2) # 2-digit NDCs
67
109
 
68
110
  # France.
69
111
  #
70
- country '33', fixed(1) >> split(2,2,2,2) # :service? => /^8.*$/, :mobile? => /^[67].*$/
112
+ country '33',
113
+ trunk('0') |
114
+ fixed(1) >> split(2,2,2,2) # :service? => /^8.*$/, :mobile? => /^[67].*$/
71
115
 
72
116
  # Spain.
73
117
  #
118
+ # http://www.minetur.gob.es/telecomunicaciones/es-es/servicios/numeracion/paginas/plan.aspx
119
+ #
74
120
  country '34',
75
- fixed(2) >> split(3,4)
121
+ match(/^([67]\d{2})\d+$/) >> split(3,3) | # Mobile
122
+ match(/^([89]0\d)\d+$/) >> split(3,3) | # Special 80X & 90X numbers
123
+ one_of(%w(91 93)) >> split(3,2,2) | # Landline large regions
124
+ match(/^(9\d{2})\d+$/) >> split(2,2,2) | # Landline
125
+ fixed(3, :zero => false) >> split(3,3)
76
126
 
77
127
  # Hungary.
78
128
  #
79
- # TODO Mobile.
129
+ # http://webpub-ext.nmhh.hu/aga/foldr/DoIndexAction.do
80
130
  #
81
131
  country '36',
82
- one_of('104','105','107','112') >> split(3,3) | # Service
83
- one_of('1') >> split(3,4) | # Budapest
84
- fixed(2) >> split(3,4) # 2-digit NDCs
132
+ trunk('06', normalize: false) |
133
+ one_of('104', '105', '107', '112') >> split(3,3) | # Service
134
+ one_of('1') >> split(3,4) | # Budapest
135
+ one_of('20', '30', '31', '50', '70') >> split(3,4) | # Mobile
136
+ one_of('21') >> split(3,4) | # VOIP
137
+ one_of('40', '80', '90', '91') >> split(3,3) | # Special charged numbers
138
+ one_of('51') >> split(3,3) | # Corporate network, M2M
139
+ one_of('38') >> split(3,4) | # Corporate network, M2M
140
+ one_of('71') >> split(5,5) | # M2M Numbers
141
+ fixed(2) >> split(3,3) # Geographic numbers
85
142
 
86
143
  # country '39' # Italy, see special file.
87
144
 
88
145
  # Romania.
89
146
  #
90
147
  country '40',
148
+ trunk('0') |
91
149
  match(/^(112|800|90[036])\d+$/) >> split(3,3) | # Service
92
- match(/^(7[1-8])\d+$/) >> split(3,4) | # Mobile
150
+ match(/^(7[1-9])\d+$/) >> split(3,4) | # Mobile
93
151
  one_of('21', '31') >> split(3,4) | # Bucureşti
94
- fixed(3) >> split(3,4) # 3-digit NDCs
152
+ fixed(3) >> split(3,3) # 3-digit NDCs
95
153
 
96
154
  # Switzerland.
97
155
  #
98
156
  country '41',
99
- match(/^(8(00|4[0248]))\d+$/) >> split(3,3) |
100
- fixed(2) >> split(3,2,2)
101
-
157
+ trunk('0', normalize: true) |
158
+ match(/^(860)\d+$/) >> split(2, 3, 2, 2) | # Voice Mail access
159
+ match(/^(8(?:00|4[0248]))\d+$/) >> split(3,3) | # Freecall/Shared Cost
160
+ match(/^(90[016])\d+$/) >> split(3,3) | # Business
161
+ fixed(2) >> split(3,2,2)
102
162
 
103
163
  # country '43' # Austria, see special file.
104
164
  # country '44' # UnitedKingdom, see special file.
@@ -106,7 +166,7 @@ Phony.define do
106
166
  # Denmark.
107
167
  #
108
168
  country '45',
109
- none >> split(2,2,2,2)
169
+ none >> split(2,2,2,2..2)
110
170
 
111
171
  # country '46' # Sweden, see special file.
112
172
 
@@ -122,40 +182,40 @@ Phony.define do
122
182
  # Note: http://wapedia.mobi/en/Telephone_numbers_in_Poland, mobile not yet correct
123
183
  #
124
184
  country '48',
125
- match(/^(5[013]\d|6[069]\d|7[02389]\d|80[01]|88\d)/) >> split(3,3) |
185
+ match(/^(45\d|5[0137]\d|6[069]\d|7[02389]\d|80[01]|88\d)/) >> split(3,3) |
126
186
  fixed(2) >> split(3,2,2)
127
187
 
128
188
  # country '49' # Germany, see special file.
129
189
 
130
190
  # Peru.
131
- #
191
+ # Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Peru
192
+ # Note: https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PE
132
193
  country '51',
133
194
  one_of('103', '105') >> split(3,3) | # Service.
134
- one_of('1', '9') >> split(4,4) | # Lima and mobile.
135
- fixed(2) >> split(4,4) # 2-digit NDCs.
195
+ one_of('9') >> split(4,4) | # Mobile.
196
+ one_of('1') >> split(3,4) | # Lima.
197
+ fixed(2) >> split(3,3) # 2-digit NDCs.
136
198
 
137
199
  # Mexico.
138
200
  #
201
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Mexico
202
+ # http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers#Mexico
139
203
  country '52',
140
- match(/^(0\d{2})\d+$/) >> split(2,2,2,2) |
141
- match(/^(33|55|81)\d+$/) >> split(2,2,2,2) |
142
- match(/^(\d{3})\d+$/) >> split(3,2,2) # catchall.
204
+ match(/^(0\d{1,2})\d{10}$/) >> split(3,3,4) | # prefixed numbers from within Mexico (e.g. 045 + 10 digits or 02 + 10 digits)
205
+ match(/^(1)(33|55|81)\d{8}$/) >> split(2,4,4) | # Mexico D.F, Guadalajara, Monterrey cell phone from abroad (e.g. 52 1 55 xxxx xxxx)
206
+ match(/^(33|55|81)\d{8}$/) >> split(4,4) | # Mexico D.F, Guadalajara, Monterrey from within Mexico
207
+ match(/^(1)(\d{3})\d{7}$/) >> split(3,3,4) | # cell phone from abroad
208
+ match(/^(\d{3})\d{7}$/) >> split(3,4) # catchall.
143
209
 
144
210
  # Cuba.
145
211
  #
146
212
  country '53',
147
- match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
213
+ match(/^(5\d{3})\d+$/) >> split(4) | # Mobile
148
214
  match(/^(7|2[123]|4[1-8]|3[1-3])/) >> split(7) | # Short NDCs
149
- fixed(3) >> split(7) # 3-digit NDCs
215
+ fixed(3) >> split(7) # 3-digit NDCs
150
216
 
151
217
  # Argentine Republic.
152
- #
153
- country '54',
154
- one_of('11', '911') >> split(4,4) | # Fixed & Mobile
155
- match(/^(22[0137]|237|26[14]|29[179]|34[1235]|35[138]|38[1578])/) >> split(3,4) | # Fixed
156
- match(/^(922[0137]|9237|926[14]|929[179]|934[1235]|935[138]|938[1578])/) >> split(3,4) | # Mobile
157
- match(/^(9\d{4})/) >> split(2,4) | # Mobile
158
- fixed(4) >> split(2,4) # Fixed
218
+ # country '54' # argentina, see special file.
159
219
 
160
220
  # Brazil (Federative Republic of).
161
221
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Brazil
@@ -164,194 +224,354 @@ Phony.define do
164
224
  # Chile.
165
225
  #
166
226
  country '56',
167
- match(/^(13[0-79]|14[79])\d+$/) >> split(3,3) | # Service
168
- one_of('2', '9') >> split(8) | # Santiago, Mobile
169
- fixed(2) >> split(8) # 2-digit NDCs
227
+ match(/^(13[0-79]|14[79])\d+$/) >> split(3,3) | # Service
228
+ one_of('2', '9') >> split(8) | # Santiago, Mobile
229
+ fixed(2) >> split(8) # 2-digit NDCs
170
230
 
171
- # TODO Colombia.
172
- #
173
- country '57', todo
231
+ # Colombia.
232
+ # http://www.itu.int/oth/T020200002C/en
233
+ country '57',
234
+ match(/\A(3\d\d)\d+\z/) >> split(3,4) | # mobile (300 310 311 312 313 315 316)
235
+ match(/\A(60\d)\d+\z/) >> split(3,4) |
236
+ fixed(1) >> split(3,4)
174
237
 
175
238
  # Venezuela (Bolivarian Republic of)
176
239
  #
177
240
  country '58',
178
- fixed(3) >> split(7)
241
+ fixed(3) >> split(7)
179
242
 
180
243
  # country '60' # Malaysia, see special file.
181
244
 
182
245
  # Australia.
183
246
  #
184
247
  country '61',
185
- match(/^(4\d\d)\d+$/) >> split(3,3) | # Mobile
186
- fixed(1) >> split(4,4) # Rest
187
-
188
- # Indonesia (Republic of)
189
- country '62',
190
- one_of('21','22','24','31') >> split(7) |
191
- one_of('21','22','24','31') >> split(8) |
192
- fixed(3) >> split(5) |
193
- fixed(3) >> split(6) |
194
- fixed(3) >> split(7) |
195
- fixed(3) >> split(8)
196
-
197
- country '63', todo # TODO Philippines (Republic of the)
248
+ trunk('0', format: false) |
249
+ match(/^(4\d\d)\d+$/) >> split(3,3) | # Mobile
250
+ match(/^(1800)\d+$/) >> split(3,3) | # 1800 free call
251
+ match(/^(1300)\d+$/) >> split(3,3) | # 1300 local rate
252
+ match(/^(13)\d+$/) >> split(2,2) | # 13 local rate
253
+ fixed(1) >> split(4,4) # Rest
254
+
255
+ # country '62' # Indonesia (Republic of), see special file
256
+
257
+ # Philippines (Republic of the)
258
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PH
259
+ country '63',
260
+ trunk('0') |
261
+ # 7/10 digits for area code '2'.
262
+ match(/\A(2)\d{10}\z/) >> split(10) |
263
+ match(/\A(2)\d{8}\z/) >> split(8) |
264
+ one_of('2') >> split(7) |
265
+ # mobile
266
+ match(/\A([89]\d\d)\d{7}\z/) >> split(7) |
267
+ match(/\A(9\d\d)\d+\z/) >> split(6) |
268
+ #
269
+ fixed(2) >> split(7)
198
270
 
199
271
  # New Zealand.
200
272
  #
201
- # TODO Mobile?
202
- #
203
273
  country '64',
204
- fixed(1) >> split(3,4)
274
+ trunk('0') |
275
+ match(/^(2\d)\d{7}$/) >> split(3,4) | # Mobile
276
+ match(/^(2\d)\d{6}$/) >> split(3,3) |
277
+ match(/^(2\d)\d{8}$/) >> split(2,3,3) |
278
+ match(/^(800)\d{6}$/) >> split(3,3) | # International 800 service where agreed
279
+ match(/^(800)\d{7}$/) >> split(3,4) | # International 800 service where agreed
280
+ fixed(1) >> split(3,4) # Rest
205
281
 
206
282
  # Singapore (Republic of).
207
283
  #
208
284
  country '65',
209
- none >> split(4,4) # TODO Short Codes.
285
+ none >> matched_split(
286
+ /^(800)\d{7}$/ => [3,3,4], # International Toll Free Service (ITFS) and Home Country Direct Service (HCDS) Numbers
287
+ /^\d{8}$/ => [4,4] # TODO Short Codes
288
+ )
210
289
 
211
290
  # Thailand.
212
291
  #
213
292
  country '66',
214
- one_of('2') >> split(3,4) | # Bangkok
215
- fixed(2) >> split(3,3) # Rest
293
+ trunk('0') |
294
+ match(/\A([689]\d\d)\d+\z/) >> split(3,3) | # mobile
295
+ one_of('2') >> split(3,4) | # Bangkok
296
+ fixed(2) >> split(3,3) # Rest
216
297
 
217
- country '81', todo # TODO Japan
298
+ # country '81' # Japan, see special file.
218
299
 
219
300
  # country '82' # SouthKorea, see special file.
220
301
 
221
- country '84', # Viet Nam (Socialist Republic of)
222
- one_of('4', '8') >> split(7) |
223
- match(/^(2[025679]|3[0136789]|5[23456789]|6[01234678]|7[02345679]|9[0-8])\d/) >> split(6) |
224
- fixed(3) >> split(5)
225
-
302
+ # country '84' # Vietnam, see special file.
226
303
 
227
304
  # country '86' # China, see special file.
228
305
 
229
306
  # Turkey.
230
307
  #
231
308
  country '90',
232
- fixed(3) >> split(3,4) # Wiki says 7, but the examples say 3, 4.
309
+ trunk('0') |
310
+ fixed(3) >> split(3,4) # Wiki says 7, but the examples say 3, 4.
233
311
 
234
- country '91', todo # TODO India (Republic of)
235
- country '92', todo # TODO Pakistan (Islamic Republic of), http://en.wikipedia.org/wiki/Telephone_numbers_in_Pakistan, NDC 2-5
312
+ # country '91' # India (Republic of) see special file
313
+
314
+ # country '92' # Pakistan (Islamic Republic of), see special file.
236
315
 
237
316
  # Afghanistan.
238
317
  #
239
318
  # From http://www.wtng.info/wtng-93-af.html
240
319
  #
241
- country '93', fixed(2) >> split(7) # Note: the document says 6, but the examples use 7.
320
+ country '93', fixed(2) >> split(7) # Note: the document says 6, but the examples use 7.
321
+
322
+ country '94', # TODO Sri Lanka (Democratic Socialist Republic of)
323
+ fixed(2) >> split(3,2,2)
242
324
 
243
- country '94', fixed(2) >> split(3,2,2) # TODO Sri Lanka (Democratic Socialist Republic of)
244
- country '95', fixed(2) >> split(3,2,2) # TODO Myanmar (Union of)
245
- country '98', fixed(2) >> split(3,2,2) # TODO Iran (Islamic Republic of)
325
+ #country '95' # Myanmar, see special file.
326
+
327
+ country '98', # Iran (Islamic Republic of)
328
+ one_of('21') >> split(4,4) | # Teheran
329
+ fixed(3) >> split(3,4)
246
330
 
247
331
  country '210', todo # -
248
- country '211', todo # South Sudan
249
- country '212', fixed(2) >> split(4,3) # Morocco
250
- country '213', fixed(2) >> split(3,4) # Algeria
332
+ country '211', fixed(3) >> split(3,3) # South Sudan, http://www.wtng.info/wtng-211-ss.html
333
+
334
+ country '212', # Morocco
335
+ trunk('0') |
336
+ one_of('6') >> split(2,2,2,2) | # mobile
337
+ fixed(2) >> split(4,3)
338
+
339
+ country '213', fixed(2) >> split(3,4) # Algeria
251
340
  country '214', todo # -
252
341
  country '215', todo # -
253
- country '216', fixed(1) >> split(3,4) # Tunisia
342
+ country '216', fixed(1) >> split(3,4) # Tunisia
254
343
  country '217', todo # -
255
- country '218', todo # Lybia
344
+
345
+ # country '218' # Lybia, see special file
346
+
256
347
  country '219', todo # -
257
348
 
258
- country '220', todo # Gambia
259
- country '221', todo # Senegal
260
- country '222', todo # Mauritania
261
- country '223', todo # Mali
262
- country '224', todo # Guinea
263
- country '225', todo # Côte d'Ivoire
264
- country '226', todo # Burkina Faso
265
- country '227', todo # Niger
266
- country '228', todo # Togolese Republic
267
- country '229', todo # Benin
268
-
269
- country '230', todo # Mauritius
270
- country '231', todo # Liberia
271
- country '232', todo # Sierra Leone
349
+ country '220', none >> split(3,4) # Gambia http://www.wtng.info/wtng-220-gm.html
350
+ country '221', none >> split(4,5) # Senegal http://www.wtng.info/wtng-221-sn.html
351
+ country '222', none >> split(4,4) # Mauritania http://www.wtng.info/wtng-222-mr.html
352
+ country '223', none >> split(4,4) # Mali http://www.wtng.info/wtng-223-ml.html
353
+
354
+ # country '224' # Guinea, see special file
355
+
356
+ # Côte d'Ivoire
357
+ # http://www.wtng.info/wtng-225-ci.html
358
+ # https://www.itu.int/dms_pub/itu-t/oth/02/02/T02020000310006PDFE.pdf
359
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Ivory_Coast
360
+ #
361
+ # There is no trunk code for this country and several of the mobile prefixes start with 0
362
+ country '225',
363
+ trunk('', :normalize => false) |
364
+ fixed(2) >> split(2,2,2,2)
365
+
366
+ country '226', none >> split(4,4) # Burkina Faso http://www.wtng.info/wtng-226-bf.html
367
+ country '227', none >> split(4,4) # Niger http://www.wtng.info/wtng-227-ne.html
368
+ country '228', none >> split(4,4) # Togolese Republic http://www.wtng.info/wtng-228-tg.html
369
+ country '229', none >> split(4,4) # Benin http://www.itu.int/oth/T0202000017/en
370
+
371
+ country '230', none >> split(4,4) # Mauritius http://www.wtng.info/wtng-230-mu.html
372
+
373
+ # Liberia
374
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LR
375
+ country '231',
376
+ none >> matched_split(
377
+ /\A[23]\d+\z/ => [4,4], # LIBTELCO, TEMAS
378
+ /\A[4568]\d+\z/ => [4,3], # mobile Lonestar, Libercell, Comium Liberia Inc.
379
+ /\A77\d+\z/ => [2,3,4], # http://monrovia.usembassy.gov/contact.html
380
+ /\A7\d+\z/ => [4,4], # mobile Cellcom
381
+ /\A9\d+\z/ => [4,4], # premium rate Telelinks International SAL, Interactive Media Corporation
382
+ )
383
+
384
+ country '232', fixed(2) >> split(3, 3) # Sierra Leone http://www.wtng.info/wtng-232-sl.html
272
385
 
273
386
  # Ghana
274
387
  #
275
388
  # From http://www.itu.int/oth/T0202000052/en
389
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Ghana
276
390
  #
277
- country '233', fixed(2) >> split(3,4)
391
+ country '233', trunk('0') | fixed(2) >> split(3,4)
278
392
 
279
393
  # Nigeria
280
- # Wikipedia says 3 4 split, many local number with no splitting
394
+ # 3 4 split for mobile and 1 digit NDC, 3 2 or 3 3 otherwise
395
+ # Many local numbers with no splitting
396
+ #
397
+ # mobile telephony number allocation taken from:
398
+ # https://www.ncc.gov.ng/technical-regulation/standards/numbering and
399
+ # https://www.itu.int/oth/T020200009C/en
281
400
  country '234',
282
- one_of('1', '2', '9') >> split(3,4) | # Lagos, Ibadan and Abuja
283
- match(/^(702\d)\d+$/) >> split(3,4) | # Mobile
284
- match(/^(70[3-9])\d+$/) >> split(3,4) | # Mobile
285
- match(/^(8[01]\d)\d+$/) >> split(3,4) | # Mobile
286
- fixed(2) >> split(3,4) # 2-digit NDC
287
-
288
-
289
- country '235', todo # Chad
290
- country '236', todo # Central African Republic
291
- country '237', todo # Cameroon
292
- country '238', todo # Cape Verde
293
- country '239', todo # Sao Tome and Principe
294
-
295
- country '240', todo # Equatorial Guinea
296
- country '241', todo # Gabonese Republic
297
- country '242', todo # Congo
298
- country '243', todo # Democratic Republic of the Congo
299
- country '244', todo # Angola
300
- country '245', todo # Guinea-Bissau
301
- country '246', todo # Diego Garcia
401
+ match(/^([7-9]0\d)\d+$/) >> split(3,4) | # Mobile
402
+ match(/^(81\d)\d+$/) >> split(3,4) | # Mobile
403
+ match(/^(91\d)\d+$/) >> split(3,4) | # Mobile
404
+ one_of('1', '2') >> split(3,3..4) | # Lagos, Ibadan
405
+ one_of('9') >> split(3,4) | # Abuja
406
+ one_of((30..79).map(&:to_s)) >> split(3,2..3) | # 2-digit NDC
407
+ one_of(%w(82 83 84 85 86 87 88 89)) >> split(3,3) # 2-digit NDC
408
+
409
+ country '235', none >> split(4,4) # Chad http://www.wtng.info/wtng-235-td.html
410
+ country '236', none >> split(4,4) # Central African Republic http://www.wtng.info/wtng-236-cf.html
411
+ country '237', none >> split(3,2,2,2) # Cameroon http://www.wtng.info/wtng-237-cm.html
412
+ country '238', none >> split(3,4) # Cape Verde http://www.wtng.info/wtng-238-cv.html
413
+ country '239', fixed(1) >> split(3,3) # Sao Tome and Principe, http://www.wtng.info/wtng-239-st.html
414
+
415
+ country '240', none >> split(3,3,3) # Equatorial Guinea
416
+ country '241',
417
+ match(/^(\d)\d{6}$/) >> split(3,3) | # Gabonese Republic http://www.wtng.info/wtng-241-ga.html
418
+ match(/^(\d\d)\d{6}$/) >> split(2,2,2) # 2019 update https://en.wikipedia.org/wiki/Telephone_numbers_in_Gabon
419
+ country '242', # Congo http://www.wtng.info/wtng-242-cg.html
420
+ trunk('', :normalize => false) |
421
+ none >> split(4,5)
422
+ country '243', fixed(2) >> split(3,4) # Democratic Republic of the Congo http://www.wtng.info/wtng-243-cd.html
423
+ country '244', one_of('321', '348', '358', '363', '364', '485', '526', '535', '546', '612', '643', '652', '655', '722', '726', '728', '729', '777') >> split(3,3) | # Angola
424
+ fixed(2) >> split(3,4)
425
+ country '245', none >> split(2,3,4) # Guinea-Bissau http://www.wtng.info/wtng-245-gw.html
426
+ country '246', none >> split(3,4) # Diego Garcia http://www.wtng.info/wtng-246-io.html
302
427
  country '247', none >> split(4) # Ascension
303
- country '248', todo # Seychelles
428
+
429
+ country '248', # Seychelles
430
+ fixed(1) >> split(2,2,2)
431
+
304
432
  country '249', fixed(2) >> split(3,4) # Sudan
305
433
 
306
434
  # Rwanda
307
435
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Rwanda
308
436
  country '250',
309
- one_of('25') >> split(7) | # Geographic, fixed
310
- match(/^(7[238])/) >> split(7) | # Non-geographic, mobile
311
- one_of('06') >> split(6) # Satellite
437
+ trunk('0') |
438
+ one_of('25') >> split(7) | # Geographic, fixed
439
+ match(/^(7[2389])/) >> split(7) | # Non-geographic, mobile
440
+ one_of('06') >> split(6) # Satellite
312
441
 
313
- country '251', todo # Ethiopia
314
- country '252', todo # Somali Democratic Republic
315
- country '253', todo # Djibouti
442
+ country '251', fixed(2) >> split(3, 4) # Ethiopia http://www.wtng.info/wtng-251-et.html
443
+
444
+ # country '252' # Somali Democratic Republic, see special file
445
+
446
+ country '253', none >> split(4, 4) # Djibouti http://www.wtng.info/wtng-253-dj.html
316
447
 
317
448
  # Kenya
318
449
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Kenya
319
- country '254',
320
- match(/^(7\d\d)/) >> split(6) | # mobile
321
- fixed(2) >> split(7) # landline
450
+ country '254',
451
+ trunk('0') |
452
+ match(/^(7\d\d)/) >> split(6) | # mobile
453
+ fixed(2) >> split(7) # landline
322
454
 
323
455
  # Tanzania.
324
456
  #
325
457
  country '255',
326
- match(/^([89]\d\d)/) >> split(3,3) | # Special/Premium.
327
- one_of('112', '118') >> split(3,3) | # Short Codes.
328
- fixed(2) >> split(3,4) # Geographic.
458
+ trunk('0') |
459
+ match(/^([89]\d\d)/) >> split(3,3) | # Special/Premium.
460
+ one_of('112', '118') >> split(3,3) | # Short Codes.
461
+ fixed(2) >> split(3,4) # Geographic.
329
462
 
330
463
  # Uganda.
331
464
  #
332
465
  country '256',
333
- match(/^(46[45]|4[78]\d)/) >> split(6) | # Geo 1.
334
- fixed(2) >> split(7) # Geo 2.
466
+ match(/^(46[45]|4[78]\d)/) >> split(6) | # Geo 1.
467
+ fixed(2) >> split(7) # Geo 2.
468
+
469
+ country '257', none >> split(4,4) # Burundi http://www.wtng.info/wtng-257-bi.html
470
+
471
+ # Mozambique, https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MZ
472
+ country '258',
473
+ one_of('600') >> split(3,3) | # audiotext
474
+ one_of('610') >> split(3,3) | # ISP
475
+ one_of('800') >> split(3,3) | # freephone
476
+ one_of('801') >> split(3,3) | # local rate
477
+ one_of('802') >> split(3,3) | # national rate
478
+ one_of(%w(251 252 271 272 281 282 293)) >> split(3,2) |
479
+ one_of(%w(21 23 24 26)) >> split(3,3) |
480
+ one_of(%w(82 84 86)) >> split(4,3) | # mobile
481
+ one_of('89') >> split(4,3) | # satellite GMPCS
482
+ one_of('7') >> split(4,4) | # universal access
483
+ one_of('9') >> split(4,4) | # premium rate
484
+ fixed(2) >> split(3,3)
335
485
 
336
- country '257', todo # Burundi
337
- country '258', todo # Mozambique
338
486
  country '259', todo # -
339
487
 
340
488
  # Zambia
341
- # http://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
489
+ # http://www.wtng.info/wtng-260-zm.html
490
+ # https://github.com/googlei18n/libphonenumber/
491
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Zambia
342
492
  country '260',
343
- match(/^(9[567])/) >> split(7) | # Mobile
344
- match(/^(21[1-8])/) >> split(6) # Geographic
345
-
346
- country '261', todo # Madagascar
347
- country '262', todo # Reunion / Mayotte (new)
348
- country '263', todo # Zimbabwe
349
- country '264', todo # Namibia
350
- country '265', todo # Malawi
351
- country '266', todo # Lesotho
352
- country '267', todo # Botswana
353
- country '268', todo # Swaziland
354
- country '269', todo # Comoros
493
+ trunk('0') |
494
+ match(/^(76|77|95|96|97)/) >> split(3, 4) | # Mobile
495
+ match(/^(800)/) >> split(3,3) | # Toll free
496
+ match(/^(21[1-8])/) >> split(6) # Fixed
497
+
498
+ # Madagascar
499
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Madagascar
500
+ # http://www.itu.int/oth/T020200007F/en
501
+ country '261',
502
+ # none >> matched_split(
503
+ # /\A20\d+\z/ => [2,2,3,2], # Telecom Malagasy (Telma)
504
+ # /\A32\d+\z/ => [2,2,3,2], # mobile Orange Madagascar
505
+ # /\A33\d+\z/ => [2,2,3,2], # mobile Airtel Madagascar
506
+ # /\A34\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
507
+ # /\A38\d+\z/ => [2,2,3,2], # mobile Telecom Malagasy (Telma)
508
+ # /\A39\d+\z => [2,2,3,2] # mobile Blueline
509
+ # ),
510
+ match(/\A(20)\d+\z/) >> split(2,3,2) | # fix Telecom Malagasy (Telma)
511
+ match(/\A(32)\d+\z/) >> split(2,3,2) | # mobile Orange Madagascar
512
+ match(/\A(33)\d+\z/) >> split(2,3,2) | # mobile Airtel Madagascar
513
+ match(/\A(34)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
514
+ match(/\A(38)\d+\z/) >> split(2,3,2) | # mobile Telecom Malagasy (Telma)
515
+ match(/\A(39)\d+\z/) >> split(2,3,2) # mobile Blueline Madagascar
516
+
517
+ country '262', # Reunion / Mayotte (new) http://www.wtng.info/wtng-262-fr.html
518
+ trunk('0') |
519
+ fixed(3) >> split(2,2,2)
520
+
521
+ # country '263' # Zimbabwe, see special file
522
+
523
+ # country '264' # Namibia, see special file
524
+
525
+ # Malawi
526
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MW
527
+ country '265',
528
+ none >> matched_split(
529
+ /\A(21|77)\d+\z/ => [3,3,3], # geographic, mobile
530
+ /\A(88|99)\d{7}\z/ => [3,3,3], # mobile
531
+ /\A18(00|11|18|20)\z/ => [4], # ISP
532
+ /\A\d+\z/ => [4,3]
533
+ )
534
+
535
+ country '266', none >> split(4, 4) # Lesotho http://www.wtng.info/wtng-266-ls.html
536
+
537
+ # Botswana
538
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
539
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=BW
540
+ country '267',
541
+ one_of(%w(463 495 499 590)) >> split(4) |
542
+ one_of(%w(24 26 29 31 46 47 49 53 54 57 58 59 62 65 68)) >> split(3,2) |
543
+ one_of('79') >> split(3,3) | # VoIP telephony
544
+ one_of('80') >> split(3,3) | # freephone
545
+ one_of('90') >> split(3,3) | # premium rate
546
+ one_of('7') >> split(4,3) | # moblie
547
+ one_of('8') >> split(4,3) | # shared cost
548
+ one_of('3') >> split(3,3) |
549
+ fixed(2) >> split(3,2)
550
+
551
+ # Swaziland http://www.wtng.info/wtng-268-sz.html
552
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SZ
553
+ country '268',
554
+ none >> matched_split(
555
+ /\A08\d+\z/ => [4,3], # freephone
556
+ /\A(2200|2300|2538|2548)\d+\z/ => [4,4], # VoIP telephony Swaziland Posts and Telecommunications Corporation (SPTC)
557
+ /\A(2400|76)\d+\z/ => [4,4], # mobile Swazi MTN Ltd
558
+ /\A(2550|2551)\d+\z/ => [4,4], # wireless geographic Swaziland Posts and Telecommunications Corporation (SPTC)
559
+ /\A(550|551)\d+\z/ => [3,4], # wireless geographic Swaziland Posts and Telecommunications Corporation (SPTC)
560
+ /\A(22|23|24|25)\d+\z/ => [4,4], # geographic SPTC
561
+ /\A77\d+\z/ => [4,4], # mobile Swaziland Posts and Telecommunications Corporation (SPTC) (CDMA)
562
+ /\A78\d+\z/ => [4,4], # mobile Swazi MTN Ltd
563
+ )
564
+
565
+ # Comoros http://www.wtng.info/wtng-269-km.html
566
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KM
567
+ country '269',
568
+ none >> matched_split(
569
+ /\A800\d+\z/ => [4,3,3], # freephone Toll-free Global269
570
+ /\A(763|77)\d+\z/ => [4,3], # geographic Comores Télécom
571
+ /\A(32|33|34)\d+\z/ => [4,3], # mobile Comores Télécom (HURI)
572
+ /\A(390|391|900|910)\d+\z/ => [4,3], # premium rate WIAIR SARL
573
+ /\A(76)\d+\z/ => [4,3] # wireless geographic Comores Télécom
574
+ )
355
575
 
356
576
  country '280', todo # -
357
577
  country '281', todo # -
@@ -363,45 +583,78 @@ Phony.define do
363
583
  country '287', todo # -
364
584
  country '288', todo # -
365
585
  country '289', todo # -
366
- country '290', todo # Saint Helena
367
-
368
- country '291', todo # Eritrea
586
+ country '290', none >> split(4) # Saint Helena http://www.wtng.info/wtng-290-sh.html
587
+ country '291', fixed(1) >> split(3, 3) # Eritrea http://www.wtng.info/wtng-291-er.html
369
588
  country '292', todo # -
370
589
  country '293', todo # -
371
590
  country '294', todo # -
372
591
  country '295', todo # -
373
592
  country '296', todo # -
374
- country '297', todo # Aruba
375
- country '298', todo # Faroe Islands
376
- country '299', todo # Greenland
593
+
594
+ # Aruba
595
+ # http://www.itu.int/dms_pub/itu-t/oth/02/02/T020200000B0001PDFE.pdf
596
+ # Landline numbers begin 52 or 58.
597
+ country '297',
598
+ fixed(3) >> split(4)
599
+
600
+ # Faroe Islands http://www.wtng.info/wtng-298-fo.html
601
+ country '298',
602
+ none >> matched_split(
603
+ /\A1\d+\z/ => [4], # universal access: Føroya Tele; ISP: Kall, Føroya Tele
604
+ /\A\d+\z/ => [3,3]
605
+ )
606
+
607
+ # Greenland http://www.wtng.info/wtng-299-gl.html
608
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
609
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=GL
610
+ country '299',
611
+ one_of(%w(199 691)) >> split(3) | # satellite; geographic: Ivittuut
612
+ one_of(%w(31 32 33 34 35 36 61 64 66 68 81 84 85 86 87 89 91 92 94 95 96 97 98 99)) >> split(4) | # geographic
613
+ one_of(%w(22 23 24 25 26 27 28 29 42 43 44 45 46 47 48 49 52 53 54 55 56 57 58 59)) >> split(4) | # mobile: Tele Greenland A/S
614
+ one_of(%w(38 39)) >> split(4) | # VoIP telephony
615
+ match(/\A(50)\d{4}\z/) >> split(4) | #| voicemail (mobile) Tele Greenland A/S
616
+ match(/\A(50)\d{6}\z/) >> split(3,3) | #|
617
+ fixed(2) >> split(4)
377
618
 
378
619
  # Gibraltar
379
620
  country '350',
380
621
  match(/^(2[012]\d)\d+$/) >> split(5) | # fixed
381
- match(/^([56]\d)\d+$/) >> split(6) | # mobile
382
- match(/^(8\d\d\d)$/) >> split(0)
622
+ match(/^([56]\d)\d+$/) >> split(6) | # mobile
623
+ match(/^(8\d\d\d)$/) >> split(0)
383
624
 
384
625
  # Portugal.
385
626
  #
386
627
  country '351',
387
- one_of('700', '800') >> split(3,3) | # Service.
388
- match(/^(9\d)\d+$/) >> split(3,4) | # Mobile.
389
- one_of('21', '22') >> split(3,4) | # Lisboa & Porto
390
- fixed(3) >> split(3,4) # 3-digit NDCs
628
+ match(/^([78]\d\d)\d+$/) >> split(3,3) | # Service.
629
+ match(/^(9\d)\d+$/) >> split(3,4) | # Mobile.
630
+ one_of('21', '22') >> split(3,4) | # Lisboa & Porto
631
+ fixed(3) >> split(3,3) # 3-digit NDCs
391
632
 
392
633
  # Luxembourg
393
634
  #
394
635
  country '352',
395
- one_of('4') >> split(2,2,2) | # Luxembourg City
396
- match(/^(2[467]\d{2})$/) >> split(2,2,2) | # 4-digit NDC
397
- match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
398
- match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
399
- match(/^([2-9]\d)/) >> split(2,2,2) # 2-digit NDC
636
+ match(/^(2[467]\d{2})\d{4}$/) >> split(2,2) | # 4-digit NDC
637
+ match(/^(6\d[18])\d+$/) >> split(3,3) | # mobile
638
+ match(/^(60\d{2})\d{8}$/) >> split(2,2,2,2) | # mobile machine to machine
639
+ match(/^((2[^467]|[3-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
640
+ match(/^((2[^467]|[3-9]\d))\d{4}$/) >> split(2,2) | # 2-digit NDC Regular 6 digits number
641
+ match(/^((2[^467]|[3-9]\d))\d{5}$/) >> split(2,2,1) | # 2-digit NDC Regular 6 digits number w/ 1 digit extension
642
+ match(/^((2[^467]|[3-9]\d))\d{6}$/) >> split(2,2,2) | # 2-digit NDC Regular 8 digits number or 6 digits with 2 digits extension
643
+ match(/^((2[^467]|[3-9]\d))\d{7}$/) >> split(2,2,3) | # 2-digit NDC Regular 6 digits with 4 digits extension
644
+ match(/^((2[^467]|[3-9]\d))\d{8}$/) >> split(2,2,4) | # 2-digit NDC Regular 6 digits number with 4 digits extension
645
+ match(/^(\d{2})\d{3}$/) >> split(2,2,1) # fallback for 5 digit number
400
646
 
401
647
  # country '353' # Republic of Ireland, see special file.
402
648
 
403
649
  country '354', none >> split(3,4) # Iceland
404
- country '355', todo # Albania
650
+
651
+ # Albania
652
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Albania
653
+ country '355', trunk('0') |
654
+ one_of('4') >> split(3,4) | # Tirana
655
+ match(/\A(6[6-9])\d*\z/) >> split(3,4) | # mobile
656
+ match(/\A(2[24]|3[2-5]|47|5[2-5]|6[6-9]|8[2-5])\d*\z/) >> split(3,3) |
657
+ fixed(3) >> split(3,2)
405
658
 
406
659
  # Malta
407
660
  # http://en.wikipedia.org/wiki/Telephone_numbers_in_Malta
@@ -410,77 +663,147 @@ Phony.define do
410
663
  match(/^(2\d\d\d)\d+$/) >> split(4) | # fixed line
411
664
  fixed(4) >> split(4) # eg. with voice mail
412
665
 
413
-
414
666
  # Cyprus
415
667
  # http://www.cytaglobal.com/cytaglobal/userfiles/NewNumberingPlan.pdf
416
- country '357', one_of('121','122','123') >> split(2,6) | # voicemail
668
+ country '357', trunk('0') |
669
+ one_of('121','122','123') >> split(2,6) | # voicemail
417
670
  fixed(2) >> split(6) # fixed & mobile
418
671
 
419
- # Finland.
672
+ # Finland
420
673
  #
421
674
  country '358',
422
- match(/^([6-8]00)\d+$/) >> split(3,3) | # Service
423
- match(/^(4\d|50)\d+$/) >> split(3,2,2) | # Mobile
424
- one_of('2','3','5','6','8','9') >> split(3,3) | # Short NDCs
425
- fixed(2) >> split(3,3) # 2-digit NDCs
426
-
427
- # Bulgaria.
675
+ trunk('0') |
676
+ match(/^(600[3-5]\d|601\d\d|700[3457]\d|7500[12]|7532[12]|7575[12]|7598[12])\d{3,4}$/) >> split(3..4) | # national service numbers, 5-digit NDC
677
+ match(/^(753[02][3-9]|7575[3-9]|7598[3-9])\d{3,5}$/) >> split(3..5) | # national subscriber numbers, 5-digit NDC
678
+ match(/^(73[0-4]\d\d)\d{5}$/) >> split(5) | # national subscriber numbers, 5-digit NDC (starting with 073)
679
+ match(/^(202[023]|209[8-9]|600[0126-9]|700[0126]|7099|800\d)\d{4,5}$/) >> split(2, 2..3) | # national service numbers, 4-digit NDCs
680
+ match(/^(606\d|70[78]\d)\d{6}$/) >> split(3, 3) | # national service numbers, 4-digit NDCs (starting with 0606/0707/0708)
681
+ match(/^(202[14-9]|209[0-7])\d{4,6}$/) >> split(3, 1..3) | # national subscriber numbers, 4-digit NDCs
682
+ match(/^(45[45789]\d)\d{2,6}$/) >> split(2, 0..4) | # mobile numbers, 4-digit NDCs
683
+ match(/^([123]00|602)\d{5,6}$/) >> split(3, 2..3) | # national service numbers, 3-digit NDCs
684
+ match(/^(10[1-9]|20[13-8]|30[1-9]|73[5-9])\d{5,7}$/) >> split(3, 2..4) | # national subscriber numbers, 3-digit NDCs
685
+ match(/^(71\d)\d{6}$/) >> split(3, 3) | # national subscriber numbers, 3-digit NDCs (starting with 071)
686
+ match(/^(73[5-9])\d{7}$/) >> split(3, 4) | # national subscriber numbers, 3-digit NDCs (starting with 073)
687
+ match(/^(43\d|45[0-36])\d{5,7}$/) >> split(3, 2..4) | # mobile numbers, 3-digit NDCs
688
+ match(/^(49\d)\d{8}$/) >> split(3, 3, 2) | # mobile numbers, 3-digit NDCs (starting with 049)
689
+ match(/^([235]9)\d{6,8}$/) >> split(3, 3, 0..2) | # national subscriber numbers, 2-digit NDCs
690
+ match(/^(4[0124678]|50)\d{4,8}$/) >> split(3, 1..5) | # mobile numbers, 2-digit NDCs
691
+ one_of('2','3','5','6','8','9') >> split(3,1..5) | # Short NDCs
692
+ fixed(2) >> split(3, 0..4) # 2-digit NDCs
693
+
694
+ # Bulgaria
428
695
  #
696
+ # Note: https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=BG
697
+ # Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Bulgaria
429
698
  country '359',
430
- fixed(2) >> split(3,2,2) # Bulgaria
699
+ trunk('0') |
700
+ match(/^(2)\d{6}$/) >> split(3,3) | # Landline Sofia (optional last digit)
701
+ match(/^(2)\d{7}$/) >> split(3,4) | # Landline Sofia (optional last digit)
702
+ match(/^(30|31|33|36|37|39|41|43\d|45|47|51|53|55|57|59)\d{5}$/) >> split(5) |
703
+ match(/^(30|31|32|33|34|35|36|37|38|39|41|42|44|45|46|47|51|52|53|54|55|56|57|58|59)\d{6}$/) >> split(2,4) |
704
+
705
+ match(/^(60|61|63|65|66|69)\d{5}$/) >> split(5) |
706
+ match(/^(60|61|62|63|64|65|66|68|69)\d{6}$/) >> split(6) |
707
+
708
+ match(/^(700|701|703|704|705|706|707|708|709)\d{5}$/) >> split(5) |
709
+ match(/^(701|702|703|704|705|706|707|708|709)\d{4}$/) >> split(4) |
710
+
711
+ match(/^(71|72|74|75|77)\d{5}$/) >> split(5) |
712
+ match(/^(71|72|73|74|75|76|77|78|79)\d{6}$/) >> split(6) |
431
713
 
432
- # Lithuania.
714
+ match(/^(80\d|81|91|93|95|97)\d{5}$/) >> split(5) |
715
+ match(/^(81|82|84|86)\d{6}$/) >> split(6) |
716
+ match(/^(87|88|89)\d{7}$/) >> split(4,3) |
717
+ match(/^(90|91|92|93|94|95|96|97|98\d|99\d)\d{6}$/) >> split(6)
718
+
719
+ # Lithuania
433
720
  #
434
721
  country '370',
722
+ trunk('8', normalize: false) |
435
723
  one_of('700', '800') >> split(2,3) | # Service
436
724
  match(/^(6\d\d)\d+$/) >> split(2,3) | # Mobile
437
725
  one_of('5') >> split(3,2,2) | # Vilnius
438
726
  one_of('37','41') >> split(2,2,2) | # Kaunas, Šiauliai
439
727
  fixed(3) >> split(1,2,2) # 3-digit NDCs.
440
728
 
441
- country '371', todo # Latvia
729
+ # country '371' # Latvia, see special file
442
730
 
443
731
  # Estonia
732
+ #
444
733
  country '372',
445
- match(/^((5\d|8[12])\d\d)\d+$/) >> split(4) | # Mobile
446
- fixed(3) >> split(4) # 3-digit NDCs
734
+ match(/^(5\d\d\d)\d+$/) >> split(3..4) | # Mobile
735
+ match(/^((?:70|8[12])\d\d)\d+$/) >> split(4) | # Mobile
736
+ fixed(3) >> split(4) # 3-digit NDCs
737
+
738
+ # country '373' # Moldova, see special file
447
739
 
448
- country '373', todo # Moldova
449
- country '374', todo # Armenia
450
- country '375', todo # Belarus
451
- country '376', todo # Andorra
740
+ country '374', match(/\A(10|55|77|9[13-9])\d*\z/) >> split(6) | # Armenia
741
+ fixed(3) >> split(5)
742
+
743
+ # Belarus
744
+ # country '375' # see special file
745
+
746
+ country '376', fixed(1) >> split(5) # Andorra
452
747
 
453
748
  # Monaco
749
+ #
454
750
  country '377',
455
- one_of('6') >> split(2,2,2,2) | # mobile
751
+ one_of('6') >> split(2,2,2,2) | # mobile
456
752
  fixed(2) >> split(2,2,2)
457
753
 
458
- country '378', todo # San Marino
754
+ # San Marino
755
+ country '378',
756
+ trunk('', :normalize => false) |
757
+ none >> matched_split(
758
+ /\A\d{6}\z/ => [3,3],
759
+ /\A\d+\z/ => [3,3,4]
760
+ )
761
+
459
762
  country '379', todo # Vatican City State
460
763
 
461
- country '380', todo # Ukraine
462
- country '381', todo # Serbia and Montenegro
463
- country '382', todo # -
464
- country '383', todo # -
465
- country '384', todo # -
764
+ # country '380' # Ukraine, see special file
765
+
766
+ # country '381' # Serbia, see special file
466
767
 
467
- # Croatia.
768
+ # country '382' # Montenegro, see special file
769
+
770
+ # Kosovo
468
771
  #
469
- country '385', one_of('1') >> split(3,5) | # Zagreb
470
- fixed(2) >> split(3,5) # 2-digit NDCs
772
+ # Note: https://en.wikipedia.org/wiki/Telephone_numbers_in_Kosovo
773
+ country '383',
774
+ trunk('0') |
775
+ fixed(2) >> split(3,3)
471
776
 
472
- country '386', fixed(2) >> split(3,2,2) # Slovenia
473
- country '387', fixed(2) >> split(3,2,2) # Bosnia and Herzegovina
474
- country '388', fixed(2) >> split(3,2,2) # Group of countries, shared code
475
- country '389', fixed(2) >> split(3,2,2) # The Former Yugoslav Republic of Macedonia
777
+ country '384', todo # -
476
778
 
477
- country '420', fixed(3) >> split(3,3) # Czech Republic
779
+ # country '385' # Croatia, see special file.
780
+
781
+ # Slovenia
782
+ # http://www.itu.int/oth/default.aspx?lang=en&parent=T02020000BE
783
+ # http://en.wikipedia.org/wiki/Telephone_numbers_in_Slovenia
784
+ country '386',
785
+ trunk('0') |
786
+ one_of('30','31','40','41','51','64','65','66','67','68','69','70','71') >> split(3,3) | # Mobile
787
+ one_of('1','2','3','4','5','7') >> split(3,4) | # Ljubljana, Maribor, Celje, Kranj, Nova Gorica, Novo mesto
788
+ fixed(3) >> split(2,3) # catchall
789
+
790
+ country '387', trunk('0') | fixed(2) >> split(3,3) # Bosnia and Herzegovina
791
+ country '388', trunk('0') | fixed(2) >> split(3,2,2) # Group of countries, shared code
792
+
793
+ # The Former Yugoslav Republic of Macedonia
794
+ country '389',
795
+ trunk('0') |
796
+ one_of('2','3','4','5','6','7','8') >> split(3,4)
797
+
798
+ country '420', fixed(3) >> split(3,3) # Czech Republic
478
799
 
479
800
  # Slovak Republic.
480
801
  #
481
- country '421', match(/^(9\d\d).+$/) >> split(6) | # Mobile
482
- one_of('2') >> split(8) | # Bratislava
483
- fixed(2) >> split(7) # 2-digit NDCs
802
+ country '421', match(/^(9\d\d).+$/) >> split(6) | # Mobile
803
+ match(/\A(2)1\d{2,4}\z/) >> split(3..5) | # Bratislava Short
804
+ match(/\A(\d{2})1\d{2,4}\z/) >> split(3..5) | # 2-digit NDCs Short
805
+ one_of('2') >> split(8) | # Bratislava
806
+ fixed(2) >> split(7) # 2-digit NDCs
484
807
 
485
808
  country '422', todo # Spare code
486
809
  country '423', none >> split(3,2,2) # Liechtenstein (Principality of)
@@ -491,53 +814,183 @@ Phony.define do
491
814
  country '428', todo # -
492
815
  country '429', todo # -
493
816
 
494
- country '500', todo # Falkland Islands (Malvinas)
495
- country '501', todo # Belize
496
- country '502', todo # Guatemala (Republic of)
497
- country '503', todo # El Salvador (Republic of)
498
- country '504', todo # Honduras (Republic of)
499
- country '505', todo # Nicaragua
500
- country '506', todo # Costa Rica
501
- country '507', todo # Panama (Republic of)
502
- country '508', todo # Saint Pierre and Miquelon (Collectivité territoriale de la République française)
503
- country '509', todo # Haiti (Republic of)
504
-
505
- country '590', todo # Guadeloupe (French Department of)
506
- country '591', todo # Bolivia (Republic of)
507
- country '592', todo # Guyana
508
- country '593', todo # Ecuador
509
- country '594', todo # French Guiana (French Department of)
510
- country '595', todo # Paraguay (Republic of)
511
- country '596', todo # Martinique (French Department of)
512
- country '597', todo # Suriname (Republic of)
513
- country '598', todo # Uruguay (Eastern Republic of)
514
- country '599', todo # Netherlands Antilles
515
-
516
- country '670', todo # Democratic Republic of Timor-Leste
817
+ country '500', none >> split(2,3) # Falkland Islands (Malvinas) http://www.wtng.info/wtng-500-fk.html
818
+ country '501', fixed(3) >> split(4) # Belize
819
+
820
+ # Guatemala (Republic of) http://www.wtng.info/wtng-502-gt.html
821
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
822
+ #
823
+ country '502',
824
+ one_of('19') >> split(3,3,3) | # premium rate
825
+ fixed(1) >> split(3,4)
826
+
827
+ # El Salvador (Republic of)
828
+ country '503', fixed(4) >> split(4)
829
+
830
+ # Honduras (Republic of) http://www.wtng.info/wtng-504-hn.html
831
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
832
+ country '504',
833
+ one_of('800') >> split(3,4) | # freephone
834
+ fixed(2) >> split(3,3) # geographic, mobile
835
+
836
+ # Nicaragua http://www.wtng.info/wtng-505-ni.html
837
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
838
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=NI
839
+ country '505',
840
+ one_of('9') >> split(3,3) | # premium rate
841
+ fixed(2) >> split(3,3) # geographic, mobile
842
+
843
+ # Costa Rica http://www.wtng.info/wtng-506-cr.html
844
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
845
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=CR
846
+ country '506',
847
+ one_of('800') >> split(3,4) | # freephone
848
+ one_of(%w(905 909)) >> split(3,4) | # premium rate
849
+ fixed(1) >> split(3,4) # geographic
850
+
851
+ # Panama (Republic of) http://www.wtng.info/wtng-507-pa.html
852
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
853
+ country '507',
854
+ one_of(%w(800 809)) >> split(4) | # freephone
855
+ one_of('6') >> split(3,4) | # mobile
856
+ fixed(1) >> split(3,3) # geographic, VoIP telephony, mobile, premium rate, shared cost, pager
857
+
858
+ country '508', none >> split(3, 3) # Saint Pierre and Miquelon (Collectivité territoriale de la République française) http://www.wtng.info/wtng-508-pm.html
859
+
860
+ country '509', # Haiti (Republic of)
861
+ fixed(2) >> split(2,4)
862
+
863
+ # Guadeloupe (French Department of) http://www.wtng.info/wtng-590-fr.html
864
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
865
+ country '590', trunk('0') |
866
+ fixed(3) >> split(2,2,2)
867
+
868
+ country '591', # Bolivia (Republic of) http://www.itu.int/oth/T020200001A/en
869
+ fixed(1) >> split(3,4)
870
+
871
+ # Guyana http://www.wtng.info/wtng-592-gy.html
872
+ # https://www.numberingplans.com
873
+ country '592',
874
+ one_of('10') >> split(2) | # audiotext
875
+ one_of(%w(11 16 17 18 19)) >> split(3) | # audiotext
876
+ fixed(3) >> split(4) # geographic, audiotext
877
+
878
+ # Ecuador http://www.wtng.info/wtng-593-ec.html
879
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=EC&current_page=1
880
+ # https://en.wikipedia.org/wiki/Telephone_numbers_in_Ecuador
881
+ country '593',
882
+ one_of('9') >> split(4,4) |
883
+ match(/\A([\d]{2})\d{7}\z/) >> split(3,4) |
884
+ fixed(1) >> split(3,4)
885
+
886
+ country '594', fixed(3) >> split(3, 3) # French Guiana (French Department of) http://www.wtng.info/wtng-594-fr.html
887
+
888
+ # country '595' # Paraguay (Republic of), see special file
889
+
890
+ # Martinique (French Department of) http://www.wtng.info/wtng-596-mq.html, https://www.numberingplans.com
891
+ country '596', trunk('0') |
892
+ fixed(3) >> split(2,2,2)
893
+
894
+ # Suriname (Republic of) http://www.wtng.info/wtng-597-sr.html, https://www.numberingplans.com
895
+ country '597',
896
+ none >> matched_split(
897
+ /\A[6789]\d+\z/ => [3,4], # freephone, mobile
898
+ /\A[2345]\d+\z/ => [3,3], # geographic, VoIP telephony
899
+ )
900
+
901
+ # country '598' # Uruguay (Eastern Republic of), see special file
902
+
903
+ country '599', one_of('9') >> split(3,4) | # Netherlands Antilles (Curacao)
904
+ fixed(3) >> split(4) # (other)
905
+
906
+ # Democratic Republic of Timor-Leste http://www.wtng.info/wtng-670-tl.html
907
+ country '670',
908
+ none >> matched_split(
909
+ /\A7\d+\z/ => [4,4], # mobile
910
+ /\A\d+\z/ => [3,4]
911
+ )
912
+
517
913
  country '671', todo # Spare code
518
914
  country '672', todo # Australian External Territories
519
- country '673', todo # Brunei Darussalam
520
- country '674', todo # Nauru (Republic of)
521
- country '675', todo # Papua New Guinea
522
- country '676', todo # Tonga (Kingdom of)
523
- country '677', todo # Solomon Islands
524
- country '678', todo # Vanuatu (Republic of)
525
- country '679', todo # Fiji (Republic of)
526
-
527
- country '680', todo # Palau (Republic of)
915
+ country '673', fixed(1) >> split(3, 3) # Brunei Darussalam http://www.wtng.info/wtng-673-bn.html
916
+ country '674', none >> split(3, 4) # Nauru (Republic of) http://www.wtng.info/wtng-674-nr.html
917
+
918
+ # Papua New Guinea
919
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=PG
920
+ country '675',
921
+ one_of(%w(180 181 182 183)) >> split(4) | # freephone
922
+ one_of('170') >> split(2) | # mobile
923
+ one_of('189') >> split(1) | # mobile
924
+ one_of('184') >> split(4,4) | # ISP, PSDN X.28
925
+ one_of(%w(185 270 271)) >> split(4) | # pager
926
+ one_of(%w(275 276)) >> split(4) | # satellite
927
+ one_of(%w(278 279)) >> split(2) | # satellite
928
+ one_of('115') >> split(4,4) | # voicemail (mobile)
929
+ one_of(%w(28 29)) >> split(3,2) | # pager
930
+ one_of(%w(16 18)) >> split(3,2) | # ISP
931
+ one_of(%w(70 71 72 74 75 76 78 79)) >> split(3,3) | # mobile
932
+ one_of(%w(731 732 733 734 735 736 738 739)) >> split(2,3) | # mobile
933
+ one_of(%w(770)) >> split(2,3) | # wireless geographic; Port Moresby, National Capital District
934
+ one_of(%w(771)) >> split(2,3) | # wireless geographic; Momase region
935
+ one_of(%w(772)) >> split(2,3) | # wireless geographic; Highlands region
936
+ one_of(%w(7730)) >> split(1,3) | # wireless geographic; Southern region
937
+ one_of(%w(774)) >> split(2,3) | # wireless geographic; Islands region
938
+ one_of(%w(775)) >> split(2,3) | # mobile
939
+ one_of(%w(80 81 82 83)) >> split(3,3) | # freephone
940
+ one_of(%w(90 91 92 93)) >> split(3,3) | # geographic, ISDN
941
+ one_of(%w(3 4 5 6 7 8 9)) >> split(3,3) # geographic
942
+ fixed(1) >> split(3,3) # geographic
943
+
944
+ # Tonga (Kingdom of)
945
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=TO
946
+ country '676',
947
+ none >> matched_split(
948
+ /\A(77|78|87|88|89)\d+\z/ => [2,3,2],
949
+ /\A\d+\z/ => [2,3]
950
+ )
951
+
952
+ # Solomon Islands http://www.wtng.info/wtng-677-sb.html, https://www.numberingplans.com
953
+ country '677',
954
+ none >> matched_split(
955
+ /\A7\d+\z/ => [4,3], # mobile
956
+ /\A\d+\z/ => [2,3] # freephone, geographic, mobile, VoIP telephony
957
+ )
958
+
959
+ # Vanuatu (Republic of) http://www.wtng.info/wtng-678-vu.html, https://www.numberingplans.com
960
+ country '678',
961
+ none >> matched_split(
962
+ /\A[579]\d+\z/ => [4,3], # mobile
963
+ /\A\d+\z/ => [2,3] # geographic, VoIP telephony
964
+ )
965
+
966
+ country '679', none >> split(3, 4) # Fiji (Republic of) http://www.wtng.info/wtng-679-fj.html
967
+
968
+ country '680', none >> split(3, 4) # Palau (Republic of) http://www.wtng.info/wtng-680-pw.html
528
969
  country '681', todo # Wallis and Futuna (Territoire français d'outre-mer)
529
- country '682', todo # Cook Islands
530
- country '683', todo # Niue
970
+ country '682', none >> split(2,3) # Cook Islands http://www.wtng.info/wtng-682-ck.html
971
+ country '683', none >> split(4) # Niue http://www.wtng.info/wtng-683-nu.html
531
972
  country '684', todo # -
532
- country '685', todo # Samoa (Independent State of)
533
- country '686', todo # Kiribati (Republic of)
534
- country '687', todo # New Caledonia (Territoire français d'outre-mer)
535
- country '688', todo # Tuvalu
536
- country '689', todo # French Polynesia (Territoire français d'outre-mer)
537
-
538
- country '690', todo # Tokelau
539
- country '691', todo # Micronesia (Federated States of)
540
- country '692', todo # Marshall Islands (Republic of the)
973
+
974
+ # Samoa (Independent State of)
975
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=WS
976
+ country '685',
977
+ none >> matched_split(
978
+ /\A800\d+\z/ => [3,3], # freephone
979
+ /\A830\d+\z/ => [3,3], # shared cost
980
+ /\A60\d+\z/ => [3,3], # wireless geographic
981
+ /\A(71|72|75|76|77)\d+\z/ => [3,4], # mobile
982
+ /\A84\d+\z/ => [3,4], # wireless geographic
983
+ /\A\d+\z/ => [2,3] # geographic
984
+ )
985
+
986
+ country '686', none >> split(2,3) # Kiribati (Republic of) http://www.wtng.info/wtng-686-ki.html
987
+ country '687', none >> split(3,3) # New Caledonia (Territoire français d'outre-mer) http://www.wtng.info/wtng-687-nc.html
988
+ country '688', none >> split(5) # Tuvalu http://www.wtng.info/wtng-688-tv.html
989
+ country '689', none >> split(2,2,2,2) # French Polynesia (Territoire français d'outre-mer) http://www.wtng.info/wtng-689-pf.html
990
+
991
+ country '690', fixed(1) >> split(3) # Tokelau http://www.wtng.info/wtng-690-tk.html
992
+ country '691', none >> split(3, 4) # Micronesia (Federated States of) http://www.wtng.info/wtng-691-fm.html
993
+ country '692', none >> split(3, 4) # Marshall Islands (Republic of the) http://www.wtng.info/wtng-692-mh.html
541
994
  country '693', todo # -
542
995
  country '694', todo # -
543
996
  country '695', todo # -
@@ -546,7 +999,10 @@ Phony.define do
546
999
  country '698', todo # -
547
1000
  country '699', todo # -
548
1001
 
549
- country '800', todo # International Freephone Service
1002
+ # International Freephone Service
1003
+ # https://www.itu.int/en/ITU-T/inr/unum/Pages/uifn.aspx
1004
+ country '800', none >> split(8)
1005
+
550
1006
  country '801', todo # -
551
1007
  country '802', todo # -
552
1008
  country '803', todo # -
@@ -554,7 +1010,7 @@ Phony.define do
554
1010
  country '805', todo # -
555
1011
  country '806', todo # -
556
1012
  country '807', todo # -
557
- country '808', todo # International Shared Cost Service (ISCS)
1013
+ country '808', none >> split(12) # International Shared Cost Service (ISCS)
558
1014
  country '809', todo # -
559
1015
 
560
1016
  country '830', todo # -
@@ -568,18 +1024,40 @@ Phony.define do
568
1024
  country '838', todo # -
569
1025
  country '839', todo # -
570
1026
 
571
- country '850', todo # Democratic People's Republic of Korea
1027
+ # Democratic People's Republic of Korea
1028
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=KP
1029
+ country '850',
1030
+ one_of(%w(191 192 193)) >> split(3,4) | # mobile
1031
+ one_of('2') >> matched_split(
1032
+ /\A\d{5}\z/ => [3,2],
1033
+ /\A\d{7}\z/ => [3,4],
1034
+ #/\A(880|881|882|883|885)\d+\z/ => [4,4,4,4],
1035
+ /\A\d+\z/ => [3,3,3]) |
1036
+ one_of(%w(31 39 41 45 53 57 61 67 73 79)) >> split(3,3) |
1037
+ fixed(2) >> split(3,3)
1038
+
572
1039
  country '851', todo # Spare code
573
- country '852', todo # Hong Kong, China
574
- country '853', todo # Macao, China
1040
+
1041
+ # Hong Kong, China
1042
+
1043
+ country '852',
1044
+ match(/^(800)\d+$/) >> split(2, 4) |
1045
+ none >> split(4,4)
1046
+
1047
+ # Macao, China
1048
+ country '853', # Macao, China
1049
+ match(/^(28)\d+$/) >> split(2,4) | # Landline.
1050
+ match(/^(8)\d+$/) >> split(3,4) | # Landline.
1051
+ match(/^(6)\d+$/) >> split(3,4) # Mobile.
1052
+
575
1053
  country '854', todo # Spare code
576
1054
 
577
- # Cambodia (Kingdom of)
578
- # http://en.wikipedia.org/wiki/Telephone_numbers_in_Cambodia
579
- country '855',
580
- fixed(2) >> split(3,4)
1055
+ # Lao People's Democratic Republic http://www.wtng.info/wtng-856-la.html, https://www.numberingplans.com
1056
+ country '856',
1057
+ one_of('30') >> split(3,4) | # geographic
1058
+ one_of('20') >> split(4,4) | # mobile
1059
+ fixed(2) >> split(3,3) # geographic
581
1060
 
582
- country '856', todo # Lao People's Democratic Republic
583
1061
  country '857', todo # Spare code
584
1062
  country '858', todo # Spare code
585
1063
  country '859', todo # Spare code
@@ -589,21 +1067,28 @@ Phony.define do
589
1067
  country '872', todo # Inmarsat (Pacific Ocean)
590
1068
  country '873', todo # Inmarsat (Indian Ocean)
591
1069
  country '874', todo # Inmarsat (Atlantic Ocean-West)
592
- country '875', todo # Reserved - Maritime Mobile Service Applications
593
- country '876', todo # Reserved - Maritime Mobile Service Applications
594
- country '877', todo # Reserved - Maritime Mobile Service Applications
1070
+ country '875', todo # Maritime Mobile Service Applications
1071
+ country '876', todo # Maritime Mobile Service Applications
1072
+ country '877', todo # Maritime Mobile Service Applications
595
1073
  country '878', todo # Universal Personal Telecommunication Service (UPT)
596
- country '879', todo # Reserved for national non-commercial purposes
1074
+ reserved '879' # Reserved for national non-commercial purposes
1075
+
1076
+ # Bangladesh (People's Republic of)
1077
+ # country '880' # see special file
1078
+
1079
+ # Global Mobile Satellite System (i.e. Iridium, Globalstar, etc)
1080
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=QM
1081
+ country '881', fixed(1) >> split(3,5)
597
1082
 
598
- country '880', todo # Bangladesh (People's Republic of)
599
- country '881', todo # International Mobile, shared code
600
1083
  country '882', todo # International Networks, shared code
601
1084
  country '883', todo # -
602
1085
  country '884', todo # -
603
1086
  country '885', todo # -
604
- country '886', todo # Reserved
1087
+
1088
+ # country '886' # Taiwan, see special file
1089
+
605
1090
  country '887', todo # -
606
- country '888', todo # Reserved for future global service
1091
+ reserved '888' # Reserved for future global service
607
1092
  country '889', todo # -
608
1093
 
609
1094
  country '890', todo # -
@@ -617,36 +1102,151 @@ Phony.define do
617
1102
  country '898', todo # -
618
1103
  country '899', todo # -
619
1104
 
620
- country '960', todo # Maldives (Republic of)
621
- country '961', todo # Lebanon
622
- country '962', todo # Jordan (Hashemite Kingdom of)
623
- country '963', todo # Syrian Arab Republic
624
- country '964', todo # Iraq (Republic of)
625
- country '965', todo # Kuwait (State of)
626
- country '966', todo # Saudi Arabia (Kingdom of)
627
- country '967', todo # Yemen (Republic of)
628
- country '968', todo # Oman (Sultanate of)
629
- country '969', todo # Reserved - reservation currently under investigation
630
-
631
- country '970', todo # Reserved
632
- country '971', todo # United Arab Emirates
633
- country '972', todo # Israel (State of)
634
- country '973', todo # Bahrain (Kingdom of)
635
- country '974', todo # Qatar (State of)
636
- country '975', todo # Bhutan (Kingdom of)
637
- country '976', todo # Mongolia
638
- country '977', todo # Nepal
1105
+ # Maldives (Republic of) http://www.wtng.info/wtng-960-mv.html, https://www.numberingplans.com
1106
+ country '960',
1107
+ one_of(%w(800 900)) >> split(3,4) | # freephone, premium rate
1108
+ fixed(3) >> split(4) # geographic, mobile
1109
+
1110
+ # Lebanon
1111
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
1112
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=LB
1113
+ country '961',
1114
+ one_of(%w(70 71 76 78 79)) >> split(3,3) | # mobile
1115
+ one_of(%w(90 91)) >> split(3,3) | # premium rate
1116
+ one_of(%w(80 81)) >> split(3,3) | # shared cost
1117
+ one_of(%w(1 4 5 6 7 8 9)) >> split(3,3) | # geographic
1118
+ one_of('3') >> split(3,3) | # mobile
1119
+ fixed(1) >> split(3,3)
1120
+
1121
+ # Jordan (Hashemite Kingdom of)
1122
+ country '962',
1123
+ one_of(%w(6250 8790)) >> split(4) | # wireless geographic
1124
+ one_of(%w(800 801 802 803 804 805 806 807 808 809)) >> split(3,2) | # freephone
1125
+ one_of('810') >> split(3,2) | # ISP
1126
+ one_of('900') >> split(3,2) | # premium rate
1127
+ one_of('70') >> split(3,3) | # universal access
1128
+ one_of(%w(85 87)) >> split(3,3) | # shared cost
1129
+ one_of(%w(2 3 5 6)) >> split(3,4) | # geographic
1130
+ one_of('7') >> split(4,4) | # mobile, pager
1131
+ fixed(1) >> split(3,4)
1132
+
1133
+ # Syrian Arab Republic
1134
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=SY
1135
+ country '963',
1136
+ one_of(%w(11 14 31 33)) >> split(3,4) |
1137
+ one_of(%w(12 13 15 16 21 22 23 25 34 41 43 51 52 53)) >> split(3,3) |
1138
+ one_of('4') >> split(3,4) |
1139
+ one_of('9') >> split(4,4) | # mobile
1140
+ fixed(2) >> split(3,3)
1141
+
1142
+ # Iraq (Republic of)
1143
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
1144
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=IQ
1145
+ country '964',
1146
+ one_of(%w(21 23 24 25 30 32 33 36 37 40 42 43 50 53 60 62 66)) >> split(3,3) |
1147
+ one_of(%w(71 72 73 74 75 76 77 78 79)) >> split(4,4) | # mobile
1148
+ one_of('1') >> split(3,4) |
1149
+ fixed(2) >> split(3,3)
1150
+
1151
+ # Kuwait (State of) http://www.wtng.info/wtng-965-kw.html
1152
+ country '965',
1153
+ none >> matched_split(
1154
+ /\A65816\d+\z/ => [4,4,4], # voicemail (mobile), Wataniya Telecom
1155
+ /\A1\d+\z/ => [3,4], # geographic
1156
+ /\A2\d+\z/ => [4,4], # geographic
1157
+ /\A[569]\d+\z/ => [4,4], # mobile
1158
+ /\A8\d+\z/ => [3,3], # geographic
1159
+ )
1160
+
1161
+ # country '966' # Saudi Arabia (Kingdom of), see special file.
1162
+
1163
+ # Yemen (Republic of)
1164
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
1165
+ country '967',
1166
+ one_of(%w(70 71 73 77)) >> split(3,4) | # mobile
1167
+ one_of('58') >> split(4) | # pager
1168
+ one_of('1') >> matched_split(
1169
+ /\A\d{6}\z/ => [3,3],
1170
+ /\A\d+\z/ => [3,4]) |
1171
+ one_of(%w(2 3 4 5 6 7)) >> split(3,3) |
1172
+ fixed(1) >> split(3,3)
1173
+
1174
+ # Oman (Sultanate of), https://www.numberingplans.com/?page=dialling&sub=areacodes
1175
+ country '968', fixed(2) >> split(3,3)
1176
+
1177
+ reserved '969' # Reserved - reservation currently under investigation
1178
+
1179
+ country '970', # 970 is used in those countries that block access to 972 (Israel)
1180
+ one_of('1') >> split(3,3,3) | # special numbers
1181
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
1182
+ match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4) # 2 digit ndc
1183
+
1184
+ # United Arab Emirates
1185
+ # https://www.numberingplans.com/?page=dialling&sub=areacodes
1186
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=AE
1187
+ country '971',
1188
+ one_of(%w(200 300)) >> split(3,3) | # shared cost
1189
+ one_of('600') >> split(3,3) | # national rate
1190
+ one_of(%w(500 700 900)) >> split(3,3) | # premium rate
1191
+ one_of('800') >> matched_split(
1192
+ /\A\d{2}\z/ => [2],
1193
+ /\A\d{7}\z/ => [2,3,2],
1194
+ /\A\d+\z/ => [2,3,4]) | # freephone
1195
+ one_of(%w(50 52 54 55 56 58)) >> split(3,4) | # mobile
1196
+ one_of(%w(2 3 4 6 7 9)) >> split(3,4) |
1197
+ fixed(1) >> split(3,4)
1198
+
1199
+ # Israel (State of) (also works for numbers in Palestinian territories)
1200
+ country '972',
1201
+ trunk('0') |
1202
+ one_of('1') >> split(3,3,3) | # special numbers
1203
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
1204
+ match(/^(5[012345689]|7[234679])\d+$/) >> split(3,4) # 2 digit ndc
1205
+
1206
+ country '973', none >> split(4,4..4) # Bahrain (Kingdom of) http://www.itu.int/oth/T0202000011/en
1207
+
1208
+ # Qatar (State of)
1209
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=QA
1210
+ country '974',
1211
+ one_of(%w(1245 1744)) >> split(3,3) | # voicemail
1212
+ one_of(%w(800 900)) >> split(2,2) | # freephone, audiotext
1213
+ one_of(%w(20 21 22 26)) >> split(3,2) | # pager
1214
+ one_of(%w(92 97)) >> split(3) | # mobile
1215
+ fixed(2) >> split(3,3)
1216
+
1217
+ country '975', fixed(1) >> split(3, 3) # Bhutan (Kingdom of) http://www.wtng.info/wtng-975-bt.html
1218
+
1219
+ # Mongolia
1220
+ # https://www.numberingplans.com/?page=plans&sub=phonenr&alpha_2_input=MN
1221
+ country '976',
1222
+ one_of(%w(121 122 123 221 222 223)) >> matched_split(
1223
+ /\A\d{4}\z/ => [2,2],
1224
+ /\A\d+\z/ => [2,3]) |
1225
+ one_of(%w(11 12 13 14 15 21 22 23 24 25)) >> split(3,2) |
1226
+ one_of(%w(70 75 76 77 78 79)) >> split(3,3) | # VoIP telephony
1227
+ one_of(%w(88 89 90 91 94 95 96 99)) >> split(3,3) | # mobile
1228
+ one_of(%w(50 55 56 58 92)) >> split(3,3) | # wireless geographic
1229
+ fixed(2) >> split(3,3)
1230
+
1231
+ # country '977' # Nepal, see special file
1232
+
639
1233
  country '978', todo # -
640
1234
  country '979', todo # International Premium Rate Service (IPRS)
641
1235
 
642
1236
  country '990', todo # Spare code
643
1237
  country '991', todo # Trial of a proposed new international telecommunication public correspondence service, shared code
644
- country '992', todo # Tajikistan (Republic of)
645
- country '993', todo # Turkmenistan
646
- country '994', todo # Azerbaijani Republic
647
- country '995', todo # Georgia
648
- country '996', todo # Kyrgyz Republic
1238
+
1239
+ # country '992' # Tajikistan (Republic of), see special file
1240
+
1241
+ # country '993' # Turkmenistan, see special file
1242
+
1243
+ country '994', fixed(2) >> split(7) # Azerbaijani Republic
1244
+
1245
+ # country '995' # Georgia, see special file
1246
+
1247
+ # country '996' # Kyrgyz Republic, see special file
1248
+
649
1249
  country '997', todo # Spare code
650
- country '998', todo # Uzbekistan (Republic of)
651
- country '999', todo # Reserved for possible future use within the Telecommunications for Disaster Relief (TDR) concept
1250
+ country '998', fixed(2) >> split(3, 4) # Uzbekistan (Republic of) http://www.wtng.info/wtng-998-uz.html
1251
+ reserved '999' # Reserved for possible future use within the Telecommunications for Disaster Relief (TDR) concept
652
1252
  end