-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_introduction.html
391 lines (363 loc) · 31.9 KB
/
10_introduction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html PUBLIC ""
"">
<html><head><meta charset="UTF-8" /><title>Introduction</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script><link rel="stylesheet" type="text/css" href="css/randomseed.css" /></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">Phone-number</span> <span class="project-version">8.13.6-3</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 current"><a href="10_introduction.html"><div class="inner"><span>Introduction</span></div></a></li><li class="depth-1 "><a href="30_specs.html"><div class="inner"><span>Specs and checks</span></div></a></li><li class="depth-1 "><a href="40_development.html"><div class="inner"><span>Development</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><a href="phone-number.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>phone-number</span></div></a></li><li class="depth-2 branch"><a href="phone-number.calling-code.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>calling-code</span></div></a></li><li class="depth-2 branch"><a href="phone-number.core.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>core</span></div></a></li><li class="depth-2 branch"><a href="phone-number.cost.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>cost</span></div></a></li><li class="depth-2 branch"><a href="phone-number.country-code.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>country-code</span></div></a></li><li class="depth-2 branch"><a href="phone-number.db.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>db</span></div></a></li><li class="depth-2 branch"><a href="phone-number.format.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>format</span></div></a></li><li class="depth-2 branch"><a href="phone-number.leniency.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>leniency</span></div></a></li><li class="depth-2 branch"><a href="phone-number.locale.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>locale</span></div></a></li><li class="depth-2 branch"><a href="phone-number.match.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>match</span></div></a></li><li class="depth-2 branch"><a href="phone-number.net-code.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>net-code</span></div></a></li><li class="depth-2 branch"><a href="phone-number.region.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>region</span></div></a></li><li class="depth-2 branch"><a href="phone-number.type.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>type</span></div></a></li><li class="depth-2 branch"><a href="phone-number.tz-format.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>tz-format</span></div></a></li><li class="depth-2"><a href="phone-number.util.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>util</span></div></a></li></ul></div><div class="document" id="content"><div class="doc"><div class="markdown"><h1><a href="#introduction" id="introduction"></a>Introduction</h1>
<p>The phone-number library is an interface to the <a href="https://github.com/google/libphonenumber">Libphonenumber</a> with some extra sugar. It allows to validate, inspect and generate phone numbers.</p>
<h2><a href="#installation" id="installation"></a>Installation</h2>
<p>To use phone-number in your project, add the following to dependencies section of <code>project.clj</code> or <code>build.boot</code>:</p>
<pre><code class="language-clojure">[io.randomseed/phone-number "8.13.6-3"]
</code></pre>
<p>For <code>deps.edn</code> add the following as an element of a map under <code>:deps</code> or <code>:extra-deps</code> key:</p>
<pre><code class="language-clojure">io.randomseed/phone-number {:mvn/version "8.13.6-3"}
</code></pre>
<p>You can also download JAR from <a href="https://clojars.org/io.randomseed/phone-number">Clojars</a>.</p>
<p>Additionally you can use (in your development profile) if you want to utilize specs and spec-integrated generators provided by the phone-number:</p>
<pre><code class="language-clojure">org.clojure/spec.alpha {:mvn/version "0.2.194"}
org.clojure/test.check {:mvn/version "1.1.0"}
</code></pre>
<h2><a href="#phone-number" id="phone-number"></a>Phone number</h2>
<p>A phone number is an abstract that can be a string, an integer number (with the accompanying region specification), a specially crafted map or a <code>PhoneNumber</code> object (which is the internal representation).</p>
<p>For regular operations (like validating a single number or searching for phone numbers in strings) it is enough to use data we already have (like a string or a map).</p>
<p>However, when the performance is important and there is a number of different operations to be executed on a single phone number it is advised to explicitly convert the number to its internal representation using the <a href="phone-number.core.html#var-number"><code>phone-number.core/number</code></a> function:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(let [n (phone/number "+44 29 2018 3133")] …)
(let [n (phone/number "29 2018 3133" :phone-number.region/gb)] …)
(let [n (phone/number 2920183133 :phone-number.region/gb)] …)
</code></pre>
<h3><a href="#phone-number-as-an-argument" id="phone-number-as-an-argument"></a>Phone number as an argument</h3>
<p>Other forms of a phone number that are acceptable as arguments by most of the functions this library provides include:</p>
<ul>
<li>strings (<code>"+44 29 2018 3133"</code>),</li>
<li>natural numbers (<code>2920183133</code>),</li>
<li>maps:
<ul>
<li>with <code>PhoneNumber</code> object:</li>
</ul>
</li>
</ul>
<pre><code class="language-clojure">{:phone-number/number #<Phonenumber$PhoneNumber@3edea9e6>}
</code></pre>
<pre><code>* with region code and national number format:
</code></pre>
<pre><code class="language-clojure">{:phone-number/region :gb
:phone-number.format/national "2920183133"}
</code></pre>
<pre><code>* with calling code and national number format:
</code></pre>
<pre><code class="language-clojure">{:phone-number/calling-code 44
:phone-number.format/national "2920183133"}
</code></pre>
<pre><code>* with international number format:
</code></pre>
<pre><code class="language-clojure">{:phone-number.format/international "+44 2920183133"}
</code></pre>
<p>Note that in case of natural numbers the additional region information is required (most of the functions will accept it as their second calling argument).</p>
<h3><a href="#caveats" id="caveats"></a>Caveats</h3>
<p>If your program processes a lot of phone numbers and your strategy is to keep them in a native format (a result of calling <code>phone-number.core/number</code>) then be aware that by default all <code>PhoneNumber</code> objects created will have raw input stored internally. This will affect <strong>comparison</strong> in a way that the object representing a number <code>+442920183133</code> will <strong>not be equal</strong> to the object representing the same number but with spaces (<code>+44 2920 183 133</code>). This is due to equality test based on, among others, raw input values which are used to generate the hash code of each object.</p>
<p>To work around that you have 2 choices:</p>
<ul>
<li>Use <code>phone-number.core/number-noraw</code> on input data to parse numbers without preserving raw inputs.</li>
<li>Use <code>phone-number.core/number-noraw</code> on existing objects to create raw-input-free copies.</li>
</ul>
<p>Optionally, <code>phone-number.core/number-optraw</code> may be used too, specifically in processing pipelines, in order to preserve raw input only when a created object is initialized with the existing one (an instance of <code>PhoneNumber</code>). In case of other argument types the protocol method behaves like <code>number-noraw</code>.</p>
<h3><a href="#namespace-inference" id="namespace-inference"></a>Namespace inference</h3>
<p>In the examples above some regions were set using namespace-qualified keywords and some were not. This is due to namespace inference when it comes to specifying phone number properties that are expressed as keywords.</p>
<p>When the dynamic variable <a href="phone-number.core.html#var-*inferred-namespaces*"><code>phone-number.core/*inferred-namespaces*</code></a> is set to <code>true</code> (which is the default setting) all functions that require keyword arguments will automatically enrich simple keywords to be namespace-qualified. That affects:</p>
<ul>
<li>region codes (e.g. <code>:pl</code> becomes <code>:phone-number.region/pl</code>),</li>
<li>number types (e.g. <code>:mobile</code> becomes <code>:phone-number.type/mobile</code>),</li>
<li>number formats (e.g. <code>:international</code> becomes <code>:phone-number.format/international</code>),</li>
<li>time zone formats (e.g. <code>:short</code> becomes <code>:phone-number.tz-format/short</code>).</li>
</ul>
<h2><a href="#phone-number-properties" id="phone-number-properties"></a>Phone number properties</h2>
<p>To get some specific property of a phone number use one of the functions grouped in <a href="phone-number.core.html"><code>phone-number.core</code></a> namespace.</p>
<p>There is also the <a href="phone-number.core.html#var-info"><code>info</code></a> function that produces a map with most of the properties:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/info "+44 29 2018 3133")
{:phone-number/country-code 44,
:phone-number/geographical? true,
:phone-number/location "Cardiff",
:phone-number/possible? true,
:phone-number/region :phone-number.region/gb,
:phone-number/dialing-region :phone-number.region/gb,
:phone-number.dialing-region/derived? true,
:phone-number.dialing-region/defaulted? false,
:phone-number.dialing-region/valid-for? true,
:phone-number/type :phone-number.type/fixed-line,
:phone-number/valid? true,
:phone-number.format/e164 "+442920183133",
:phone-number.format/international "+44 29 2018 3133",
:phone-number.format/national "029 2018 3133",
:phone-number.format/raw-input "+44 29 2018 3133",
:phone-number.format/rfc3966 "tel:+44-29-2018-3133",
:phone-number.tz-format/full-standalone ("Greenwich Mean Time"),
:phone-number.tz-format/id ("Europe/London"),
:phone-number.tz-format/short-standalone("GMT"),
:phone.number.short/possible? false,
:phone.number.short/valid? false}
</code></pre>
<p>The <code>info</code> function (like most of the functions operating on phone numbers) takes an additional, second argument which should be a <strong>region code</strong>. It is used only when the given phone number was expressed in a format that cannot provide such information (a string without calling code, a natural number, a map without any entry containing region or calling code).</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/info "0491 570 006" :phone-number.region/au)
{:phone-number/calling-code 61,
:phone-number/carrier "Telstra",
:phone-number/geographical? false,
:phone-number/possible? true,
:phone-number/region :phone-number.region/au,
:phone-number/dialing-region :phone-number.region/au,
:phone-number.dialing-region/derived? true,
:phone-number.dialing-region/defaulted? false,
:phone-number.dialing-region/valid-for? true,
:phone-number/type :phone-number.type/mobile,
:phone-number/valid? true,
:phone-number.format/e164 "+61491570006",
:phone-number.format/international "+61 491 570 006",
:phone-number.format/national "0491 570 006",
:phone-number.format/raw-input "0491 570 006",
:phone-number.format/rfc3966 "tel:+61-491-570-006",
:phone-number.tz-format/full-standalone ("Central Australia Time"
"Australian Central Western Time"
"Lord Howe Time"
"Western Australia Time"
"Eastern Australia Time"
"Christmas Island Time"
"Cocos Islands Time"),
:phone-number.tz-format/id ("Australia/Adelaide"
"Australia/Eucla"
"Australia/Lord_Howe"
"Australia/Perth"
"Australia/Sydney"
"Indian/Christmas"
"Indian/Cocos"),
:phone-number.tz-format/short-standalone ("ACT"
"ACWT"
"LHT"
"AWT"
"AET"
"CIT"
"CCT"),
:phone.number.short/possible? false,
:phone.number.short/valid? false}
</code></pre>
<p>It is worth to note that the time zone information was presented in English (being the default locale for the system). That behavior can be changed with a third, optional argument, which should be a <code>java.util.Locale</code> instance or a value that can be converted to it (a string, a keyword, a symbol).</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/info "0491 570 006" :au :pl)
{:phone-number/calling-code 61,
:phone-number/carrier "Telstra",
:phone-number/geographical? false,
:phone-number/possible? true,
:phone-number/region :phone-number.region/au,
:phone-number/dialing-region :phone-number.region/au,
:phone-number.dialing-region/derived? true,
:phone-number.dialing-region/defaulted? false,
:phone-number.dialing-region/valid-for? true,
:phone-number/type :phone-number.type/mobile,
:phone-number/valid? true,
:phone-number.format/e164 "+61491570006",
:phone-number.format/international "+61 491 570 006",
:phone-number.format/national "0491 570 006",
:phone-number.format/raw-input "0491 570 006",
:phone-number.format/rfc3966 "tel:+61-491-570-006",
:phone-number.tz-format/full-standalone ("Czas środkowoaustralijski"
"Czas środkowo-zachodnioaustralijski"
"Lord Howe"
"Czas zachodnioaustralijski"
"Czas wschodnioaustraliski"
"Christmas Island Time"
"Cocos Islands Time"),
:phone-number.tz-format/id ("Australia/Adelaide"
"Australia/Eucla"
"Australia/Lord_Howe"
"Australia/Perth"
"Australia/Sydney"
"Indian/Christmas"
"Indian/Cocos"),
:phone-number.tz-format/short-standalone ("ACT"
"ACWT"
"LHT"
"AWT"
"AET"
"CIT"
"CCT"),
:phone.number.short/possible? false,
:phone.number.short/valid? false}
</code></pre>
<h3><a href="#short-phone-numbers" id="short-phone-numbers"></a>Short phone numbers</h3>
<p>There is a special class of phone numbers called <strong>short numbers</strong>. These include all of the special, short phone numbers used mostly for emergency purposes but also for local services (like taxis). In the examples above we could see the keys belonging to the <code>:phone-number.short/</code> namespace which are describing short number properties. If the number is not a short number the information map will only contain <code>:phone-number.short/valid?</code> and <code>:phone-number.short/possible?</code> keys.</p>
<p>Short number example:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/info "997" :pl)
{:phone-number/calling-code 48,
:phone-number/geographical? false,
:phone-number/possible? false,
:phone-number/region :phone-number.region/pl,
:phone-number/dialing-region :phone-number.region/pl,
:phone-number.dialing-region/derived? true,
:phone-number.dialing-region/defaulted? false,
:phone-number.dialing-region/valid-for? true,
:phone-number/type :phone-number.type/unknown,
:phone-number/valid? false,
:phone-number.format/e164 "+48997",
:phone-number.format/international "+48 997",
:phone-number.format/national "997",
:phone-number.format/raw-input "997",
:phone-number.format/rfc3966 "tel:+48-997",
:phone-number.short/carrier-specific? false,
:phone-number.short/cost :phone-number.cost/toll-free,
:phone-number.short/emergency? true,
:phone-number.short/possible? true,
:phone-number.short/sms-service? false,
:phone-number.short/to-emergency? true,
:phone-number.short/valid? true}
</code></pre>
<h3><a href="#phone-number-types" id="phone-number-types"></a>Phone number types</h3>
<p>Some functions will require phone number type to be given. In is easy to get all the supported types via global variable:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
phone/types
#{:phone-number.type/fixed-line
:phone-number.type/fixed-line-or-mobile
:phone-number.type/mobile
:phone-number.type/pager
:phone-number.type/personal
:phone-number.type/premium-rate
:phone-number.type/shared-cost
:phone-number.type/toll-free
:phone-number.type/uan
:phone-number.type/unknown
:phone-number.type/voicemail
:phone-number.type/voip}
</code></pre>
<p>Note that <code>:phone-number.type/unknown</code> is valid as a property but not valid as an argument.</p>
<h3><a href="#region-codes" id="region-codes"></a>Region codes</h3>
<p><strong>Region code</strong> is alphabetic, two-letter keyword that allows phone-number functions to create, generate and match phone numbers. It is also used for reporting.</p>
<p>Region codes can be translated to <strong>country calling codes</strong> which can be observed in international phone number notations (with the plus sign in front of the number). For example the region code <code>:pl</code> (or <code>phone-number.region/pl</code>) will be represented as <code>+48</code> country code prefix.</p>
<p>It is possible to get all of the supported region codes with the <a href="phone-number.core.html#var-regions"><code>phone-number.core/regions</code></a> global variable.</p>
<h3><a href="#dialing-region-codes" id="dialing-region-codes"></a>Dialing region codes</h3>
<p><strong>Dialing region code</strong> (a.k.a calling region code) is a region code that some of the functions use as a supplementary information to establish certain properties of a number. Semantically it describes <strong>where</strong> the call is made from (what is its origin).</p>
<p>It is common to use dialing region when testing or validating short phone numbers since their properties depend on the originating region. For example the number <code>112</code> is a valid short number (see the <code>:phone-number.short/valid?</code> key in an info map) when dialed from Poland but not from USA.</p>
<p>Dialing region codes may be passed directly to functions that make use of it (and that is the first and prioritized way to obtain this information) but they can also be taken from the global dynamic variable <code>phone-number.core/*default-dialing-region*</code>. If the phone number is in a form of a map with <code>:phone-number/dialing-region</code> key present then a value associated with it will be tried before (but only if this property is not derived nor defaulted).</p>
<p>In case of <code>phone-number.core/info</code> and <code>phone-number.core/short-info</code> there is another source of getting a dialing region code which is by derivation from a region code of the number. It is tried when there is no dialing region passed as an argument, no default dialing region set and no dialing region read from a map (if a phone number is a map). The derivation is enabled by default but can be controlled using the <code>phone-number.core/*info-dialing-region-derived*</code> dynamic variable.</p>
<p>The value of dialing region will affect all of the calculated properties of the checked number that depend on it but not the one returned by the <code>phone-number.core/valid?</code> function. In its case one have to use ternary variant for the dialing region to be taken into consideration (even passing <code>nil</code> to make the function use the default). The reason behind it is that it is very rare need to test a regular number for validity with a different dialing region. In the majority of cases the returned value will be <code>false</code> and it could be a potential point of failure (or misunderstanding), especially when some default dialing region is present.</p>
<h3><a href="#calling-codes" id="calling-codes"></a>Calling codes</h3>
<p><strong>Calling code</strong> is a prefix number used to create regional or global phone number assignation. There are two types of calling codes supported:</p>
<ul>
<li><strong>country calling codes</strong> (that can be derived from region codes),</li>
<li><strong>global network calling codes</strong> that are independent of regions.</li>
</ul>
<p>It is possible for a phone number to have a calling code (which is a global one) but not a region code.</p>
<p>There are just a few functions that calling codes can be used with directly. In such cases they are expressed as positive, natural numbers.</p>
<ul>
<li>To get all country calling codes use <a href="phone-number.core.html#var-country-codes"><code>phone-number.core/country-codes</code></a>.</li>
<li>To get all global network calling codes use <a href="phone-number.core.html#var-net-codes"><code>phone-number.core/net-codes</code></a>.</li>
<li>To get all calling codes (both global and country) use <a href="phone-number.core.html#var-calling-codes"><code>phone-number.core/calling-codes</code></a>.</li>
</ul>
<p>To get the calling code of a phone number use the <a href="phone-number.core.html#var-calling-code"><code>phone-number.core/calling-code</code></a> function.</p>
<h3><a href="#formats" id="formats"></a>Formats</h3>
<p>Phone numbers can be presented in different formats. To get all possible formats use the <a href="phone-number.core.html#var-formats"><code>phone-number.core/formats</code></a> global variable:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
phone/formats
#{:phone-number.format/e164
:phone-number.format/international
:phone-number.format/national
:phone-number.format/raw-input
:phone-number.format/rfc3966
:phone-number.format/raw-input}
</code></pre>
<p>To get the phone number representation in a specific format use the <a href="phone-number.core.html#var-format"><code>phone-number.core/format</code></a> function:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/format "+442920183133" :rfc3966)
"tel:+44-29-2018-3133"
</code></pre>
<h3><a href="#time-zone-formats" id="time-zone-formats"></a>Time zone formats</h3>
<p>Some phone numbers can be indirectly associated with time zones (via geographical locations of the lines or carrier’s local offices locations). To get all possible formats of time zones use the <a href="phone-number.core.html#var-tz-formats"><code>phone-number.core/tz-formats</code></a> global variable:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
phone/tz-formats
#{:phone-number.tz-format/full
:phone-number.tz-format/full-standalone
:phone-number.tz-format/id
:phone-number.tz-format/narrow
:phone-number.tz-format/narrow-standalone
:phone-number.tz-format/short
:phone-number.tz-format/short-standalone}
</code></pre>
<p>To get time zone information for a phone number in a specified format use the <a href="phone-number.core.html#var-time-zones"><code>phone-number.core/time-zones</code></a> function:</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/time-zones "+442920183133" nil :full)
("Greenwich Mean Time")
</code></pre>
<p>We can observe that the result is a collection of strings. That’s because some phone numbers can be assigned to more than one time zone.</p>
<h2><a href="#validation" id="validation"></a>Validation</h2>
<p>To validate a phone number use the following functions:</p>
<ul>
<li><a href="phone-number.core.html#var-valid.3F"><code>phone-number.core/valid?</code></a>,</li>
<li><a href="phone-number.core.html#var-invalid.3F"><code>phone-number.core/invalid?</code></a>,</li>
<li><a href="phone-number.core.html#var-possible.3F"><code>phone-number.core/possible?</code></a>,</li>
<li><a href="phone-number.core.html#var-impossible.3F"><code>phone-number.core/impossible?</code></a>.</li>
</ul>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/valid? 8081570001 :gb) ; => true
(phone/valid? "+448081570001") ; => true
(phone/valid? 8081570001 :pl) ; => false
(phone/valid? "8081570001") ; => false
(phone/possible? "8081570001") ; => false
(phone/possible? "8081570001" :gb) ; => true
(phone/possible? "8081570001" :pl) ; => true
</code></pre>
<p>Additionally there are variants for short numbers:</p>
<ul>
<li><a href="phone-number.core.html#var-short-valid.3F"><code>phone-number.core/short-valid?</code></a>,</li>
<li><a href="phone-number.core.html#var-short-invalid.3F"><code>phone-number.core/short-invalid?</code></a>,</li>
<li><a href="phone-number.core.html#var-short-possible.3F"><code>phone-number.core/short-possible?</code></a>.</li>
</ul>
<h2><a href="#samples-generation" id="samples-generation"></a>Samples generation</h2>
<p>To generate samples of phone numbers with optional predicates controlling the properties of data use the <a href="phone-number.core.html#var-generate"><code>phone-number.core/generate</code></a> function. It tries to get the most probable samples (having the most digits randomized yet meeting the given criteria) with optional deterministic factor (random seed).</p>
<p>There are also phone number generators associated with many of the existing specs that make use of this function.</p>
<pre><code class="language-clojure">(require '[phone-number.core :as phone])
(phone/generate)
{:phone-number/info {:phone-number/country-code 213,
:phone-number/geographical? false,
:phone-number/possible? true,
:phone-number/region :phone-number.region/dz,
:phone-number/dialing-region :phone-number.region/dz,
:phone-number.dialing-region/derived? true,
:phone-number.dialing-region/defaulted? false,
:phone-number.dialing-region/valid-for? false,
:phone-number/type :phone-number.type/unknown,
:phone-number/valid? false,
:phone-number.format/e164 "+213181525997",
:phone-number.format/international "+213 181525997",
:phone-number.format/national "181525997",
:phone-number.format/rfc3966 "tel:+213-181525997",
:phone.number.short/possible? false,
:phone.number.short/valid? false},
:phone-number/number #<Phonenumber$PhoneNumber@3edea9e6>,
:phone-number.sample/digits ["+213" nil "181525997"],
:phone-number.sample/hits 10,
:phone-number.sample/max-samples 1000,
:phone-number.sample/random-seed 7521527664400716800,
:phone-number.sample/samples 11}
(require [phone-number.spec :as spec]
[clojure.spec.alpha :as s]
[clojure.spec.gen.alpha :as gen])
(gen/generate (s/gen :phone-number/valid))
{:phone-number/info #delay[{:status :pending, :val nil} 0x3810d15d],
:phone-number/number #<Phonenumber$PhoneNumber@79cc08fb>,
:phone-number.sample/digits ["+7" nil "937627908"],
:phone-number.sample/hits 11,
:phone-number.sample/max-samples 150,
:phone-number.sample/random-seed 7581363778716192180,
:phone-number.sample/samples 27}
(gen/generate (s/gen (s/and :phone-number/possible :phone-number/invalid)))
{:phone-number/info #delay[{:status :pending, :val nil} 0x41c0e225],
:phone-number/number #<Phonenumber$PhoneNumber@36a74c18>,
:phone-number.sample/digits ["+84" nil "0270454"],
:phone-number.sample/hits 8,
:phone-number.sample/max-samples 200,
:phone-number.sample/random-seed -9105741821593959780,
:phone-number.sample/samples 12}
</code></pre>
<h2><a href="#license" id="license"></a>License</h2>
<p>Copyright © 2020–2023 Paweł Wilk</p>
<p>Phone-number is copyrighted software owned by Paweł Wilk (<a href="mailto:pw@gnu.org">pw@gnu.org</a>). You may redistribute and/or modify this software as long as you comply with the terms of the <a href="https://github.com/randomseed-io/phone-number/blob/master/LICENSE">GNU Lesser General Public License</a> (version 3).</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div></div></div></body></html>