uk_sms_range 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/lib/uk_sms_range/version.rb +5 -0
- data/lib/uk_sms_range.rb +173 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bf2748a5e133c18c4e70dd35f446178aa7ddbda6164753b660bd0d5a8b9066f8
|
|
4
|
+
data.tar.gz: df91478d3cba88b9b045394dc045deb45e1da07d3b6d0270391478d31deefb27
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4dc8b8a187cdf6054f4265f562a177e023031e6185d6468808a25247fbaf58bbf60d75d134ae69a8be6f771ee0b142b5a6d3b551b972db900ffcf5b778278a01
|
|
7
|
+
data.tar.gz: 2b1596157eedc102876db57101e17fded4ff81f551a6a390fc2c218112cf7fb455579056c695537eae06d43b5bf3e3d1a9621cefe4167227b879314aa376044e
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CryptoeSIM
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# uk_sms_range
|
|
2
|
+
|
|
3
|
+
Normalise, format and classify UK phone numbers by Ofcom range, and get a quick answer to "will an SMS verification code reach this number?"
|
|
4
|
+
|
|
5
|
+
It works from the digits alone. No network calls, no API key, no dependencies.
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
require "uk_sms_range"
|
|
9
|
+
|
|
10
|
+
r = UkSmsRange.classify("+44 (0)7911 123456")
|
|
11
|
+
r.label # => "mobile"
|
|
12
|
+
r.e164 # => "+447911123456"
|
|
13
|
+
r.sms_likely? # => true
|
|
14
|
+
|
|
15
|
+
UkSmsRange.classify("05601 234567").note
|
|
16
|
+
# => "056 is for location-independent services, in practice VoIP. Many sign-up checks refuse it."
|
|
17
|
+
|
|
18
|
+
UkSmsRange.format("+442079460123") # => "020 7946 0123"
|
|
19
|
+
UkSmsRange.drama?("07700 900123") # => true (Ofcom reserved number)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
gem install uk_sms_range
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
or in a Gemfile: `gem "uk_sms_range"`. Ruby 2.7 or newer.
|
|
29
|
+
|
|
30
|
+
## What it tells you
|
|
31
|
+
|
|
32
|
+
`UkSmsRange.classify(number)` returns a `Result` with:
|
|
33
|
+
|
|
34
|
+
- `national` and `e164`: the number as `07911123456` and `+447911123456`
|
|
35
|
+
- `type` and `label`: which Ofcom range it is on (`:mobile`, `:voip`, `:personal`, `:geographic` and so on)
|
|
36
|
+
- `sms_likely?`: true only for ranges that normally receive text messages
|
|
37
|
+
- `drama?`: true for Ofcom's reserved drama numbers
|
|
38
|
+
- `note`: a plain-English reason when the range is unusual, or why the input was rejected
|
|
39
|
+
|
|
40
|
+
It accepts the formats people actually type: `07911 123456`, `+44 7911 123456`, `0044 7911 123456`, `+44 (0)7911 123456`, `447911123456`, with spaces, dots or dashes. It never raises on bad input; check `valid?`.
|
|
41
|
+
|
|
42
|
+
| Prefix | Range | SMS codes |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| 071 to 075, 077 to 079 | Mobile | Usually yes |
|
|
45
|
+
| 07624 | Mobile, Isle of Man | Usually yes |
|
|
46
|
+
| 070 | Personal number (call forwarding) | No |
|
|
47
|
+
| 076 (not 07624) | Radiopaging | No |
|
|
48
|
+
| 056 | VoIP, location-independent | Rarely accepted |
|
|
49
|
+
| 055 | Corporate | No |
|
|
50
|
+
| 01, 02 | Landline | No |
|
|
51
|
+
| 03 | UK-wide | No |
|
|
52
|
+
| 080 | Freephone | No |
|
|
53
|
+
| 084, 087 | Business rate | No |
|
|
54
|
+
| 09 | Premium rate | No |
|
|
55
|
+
|
|
56
|
+
## Formatting
|
|
57
|
+
|
|
58
|
+
`UkSmsRange.format` spaces numbers the way they are normally written in the UK: mobiles as 5 + 6 (`07911 123456`), London and other 02 numbers as 3 + 4 + 4 (`020 7946 0123`), the big-city 011x and 01x1 codes as 4 + 3 + 4 (`0161 496 0000`), other landlines as 5 + 6, and 03/08/09 numbers as 4 + 3 + 4. Pass `international: true` to get `+44 7911 123456`, which drops the leading 0 as it should. If you want the reasoning behind those groupings, and the mistakes that make sign-up forms reject a valid number, there is a longer [UK mobile number format guide](https://cryptoesim.io/blog/uk-mobile-number-format).
|
|
59
|
+
|
|
60
|
+
## Test numbers
|
|
61
|
+
|
|
62
|
+
Ofcom keeps blocks of numbers aside for TV and film, such as 07700 900000 to 900999 and 020 7946 0000 to 0999. They are never given to real people, so use them in fixtures, screenshots and demo data. `drama?` recognises the mobile, London, big-city, Northern Ireland, Cardiff, 01632, 0306, 0808 and 0909 blocks.
|
|
63
|
+
|
|
64
|
+
## What it can't tell you
|
|
65
|
+
|
|
66
|
+
A prefix tells you the range, not the line. It can't see whether a number is live, has been ported, or is a VoIP service that happens to use a mobile range. Line-type databases used by banks and apps go further and will often mark those as VoIP.
|
|
67
|
+
|
|
68
|
+
It also can't tell you whether a number is shared. Numbers listed on public receive-SMS websites usually pass this check because they are real mobiles, but every code sent to them is visible to anyone, and big services block them quickly. If you are working out whether a free UK number to receive SMS is good enough for a sign-up, CryptoeSIM's write-up on [free UK numbers for receiving SMS](https://cryptoesim.io/blog/free-uk-number-receive-sms) covers why codes go missing and what holds up better.
|
|
69
|
+
|
|
70
|
+
Ranges follow Ofcom's [National Telephone Numbering Plan](https://www.ofcom.org.uk/phones-and-broadband/phone-numbers/numbering). Sub-allocations change, so treat the result as a first filter, not a final answer.
|
|
71
|
+
|
|
72
|
+
## Licence
|
|
73
|
+
|
|
74
|
+
MIT. Maintained by the CryptoeSIM team.
|
data/lib/uk_sms_range.rb
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "uk_sms_range/version"
|
|
4
|
+
|
|
5
|
+
# Normalise, format and classify UK phone numbers by Ofcom range.
|
|
6
|
+
#
|
|
7
|
+
# Everything works from the dialled digits alone: no network calls and no
|
|
8
|
+
# lookup service. That means it can tell you what kind of range a number is
|
|
9
|
+
# on, but not whether the number is in service, ported, or carried over VoIP.
|
|
10
|
+
module UkSmsRange
|
|
11
|
+
# One classified number.
|
|
12
|
+
Result = Struct.new(:input, :national, :e164, :type, :label, :sms_likely,
|
|
13
|
+
:drama, :note, keyword_init: true) do
|
|
14
|
+
def valid?
|
|
15
|
+
!type.nil?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def sms_likely?
|
|
19
|
+
sms_likely == true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def drama?
|
|
23
|
+
drama == true
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_s
|
|
27
|
+
valid? ? "#{UkSmsRange.format(national)} (#{label})" : "invalid"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Prefix => [type, label, sms_likely, note]. Longest prefix wins.
|
|
32
|
+
RANGES = {
|
|
33
|
+
"07624" => [:mobile_iom, "mobile (Isle of Man)", true,
|
|
34
|
+
"Isle of Man mobile range. Dialled with +44 but not UK mainland."],
|
|
35
|
+
"070" => [:personal, "personal number", false,
|
|
36
|
+
"070 is personal numbering, a call-forwarding service rather than a mobile. " \
|
|
37
|
+
"Most apps will not send codes to it."],
|
|
38
|
+
"071" => [:mobile, "mobile", true, nil],
|
|
39
|
+
"072" => [:mobile, "mobile", true, nil],
|
|
40
|
+
"073" => [:mobile, "mobile", true, nil],
|
|
41
|
+
"074" => [:mobile, "mobile", true, nil],
|
|
42
|
+
"075" => [:mobile, "mobile", true, nil],
|
|
43
|
+
"076" => [:paging, "radiopaging", false,
|
|
44
|
+
"076 (apart from 07624) is radiopaging and does not take SMS."],
|
|
45
|
+
"077" => [:mobile, "mobile", true, nil],
|
|
46
|
+
"078" => [:mobile, "mobile", true, nil],
|
|
47
|
+
"079" => [:mobile, "mobile", true, nil],
|
|
48
|
+
"056" => [:voip, "VoIP (location-independent)", false,
|
|
49
|
+
"056 is for location-independent services, in practice VoIP. " \
|
|
50
|
+
"Many sign-up checks refuse it."],
|
|
51
|
+
"055" => [:corporate, "corporate", false, "055 numbers usually route to a company phone system."],
|
|
52
|
+
"0500" => [:freephone_closed, "old freephone (closed 2017)", false,
|
|
53
|
+
"0500 freephone numbers were withdrawn in June 2017."],
|
|
54
|
+
"080" => [:freephone, "freephone", false, nil],
|
|
55
|
+
"084" => [:business_rate, "business rate", false, nil],
|
|
56
|
+
"087" => [:business_rate, "business rate", false, nil],
|
|
57
|
+
"09" => [:premium, "premium rate", false, nil],
|
|
58
|
+
"03" => [:non_geographic, "UK-wide (03)", false, nil],
|
|
59
|
+
"02" => [:geographic, "landline", false, nil],
|
|
60
|
+
"01" => [:geographic, "landline", false, nil]
|
|
61
|
+
}.sort_by { |prefix, _| -prefix.length }.freeze
|
|
62
|
+
|
|
63
|
+
# Ofcom keeps these blocks free for TV, radio and film. They are never
|
|
64
|
+
# issued to real subscribers, which makes them safe for tests and demos.
|
|
65
|
+
DRAMA_BLOCKS = [
|
|
66
|
+
["07700900", 0, 999],
|
|
67
|
+
["0207946", 0, 999],
|
|
68
|
+
["0113496", 0, 999], ["0114496", 0, 999], ["0115496", 0, 999],
|
|
69
|
+
["0116496", 0, 999], ["0117496", 0, 999], ["0118496", 0, 999],
|
|
70
|
+
["0121496", 0, 999], ["0131496", 0, 999], ["0141496", 0, 999],
|
|
71
|
+
["0151496", 0, 999], ["0161496", 0, 999], ["0191498", 0, 999],
|
|
72
|
+
["0289018", 0, 999], ["0292018", 0, 999],
|
|
73
|
+
["01632960", 0, 999],
|
|
74
|
+
["0306999", 0, 999], ["0808157", 0, 999], ["0909879", 0, 999]
|
|
75
|
+
].freeze
|
|
76
|
+
|
|
77
|
+
# Three-digit area codes (02x) and the four-digit 011x / 01x1 codes.
|
|
78
|
+
# Everything else on 01 uses a five-digit area code.
|
|
79
|
+
FOUR_DIGIT_AREA = /\A01(1\d|\d1)/.freeze
|
|
80
|
+
|
|
81
|
+
module_function
|
|
82
|
+
|
|
83
|
+
# "07700 900123", "+44 7700 900123", "0044 7700 900123",
|
|
84
|
+
# "+44 (0)7700 900123" and "447700900123" all become "07700900123".
|
|
85
|
+
# Returns nil when the input isn't a UK number this can read.
|
|
86
|
+
def normalise(raw)
|
|
87
|
+
return nil if raw.nil?
|
|
88
|
+
|
|
89
|
+
s = raw.to_s.strip.sub("(0)", "")
|
|
90
|
+
return nil if s.empty?
|
|
91
|
+
return nil unless s.match?(/\A\+?[\d\s\-().]+\z/)
|
|
92
|
+
|
|
93
|
+
plus = s.start_with?("+")
|
|
94
|
+
d = s.delete("^0-9")
|
|
95
|
+
if plus
|
|
96
|
+
return nil unless d.start_with?("44")
|
|
97
|
+
|
|
98
|
+
"0#{d[2..]}"
|
|
99
|
+
elsif d.start_with?("0044")
|
|
100
|
+
"0#{d[4..]}"
|
|
101
|
+
elsif d.start_with?("44") && d.length == 12
|
|
102
|
+
"0#{d[2..]}"
|
|
103
|
+
elsif d.start_with?("0")
|
|
104
|
+
d
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Classify a number. Never raises: check Result#valid? and Result#note.
|
|
109
|
+
def classify(raw)
|
|
110
|
+
n = normalise(raw)
|
|
111
|
+
unless n
|
|
112
|
+
return Result.new(input: raw, note: "Not a UK number in a format this gem understands.")
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
ok_len = n.length == 11 || (n.length == 10 && (n.start_with?("01") || n.start_with?("0800")))
|
|
116
|
+
unless ok_len
|
|
117
|
+
return Result.new(input: raw, national: n,
|
|
118
|
+
note: "Wrong length: #{n.length} digits with the leading 0 (most UK numbers have 11).")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
prefix, (type, label, sms, note) = RANGES.find { |p, _| n.start_with?(p) }
|
|
122
|
+
unless prefix
|
|
123
|
+
return Result.new(input: raw, national: n, note: "#{n[0, 2]} is not an allocated UK range.")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
Result.new(input: raw, national: n, e164: "+44#{n[1..]}", type: type, label: label,
|
|
127
|
+
sms_likely: sms, drama: drama?(n), note: note)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# True when the number sits on a range that normally receives SMS codes.
|
|
131
|
+
def sms_likely?(raw)
|
|
132
|
+
classify(raw).sms_likely?
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# True for Ofcom's reserved drama numbers (07700 900xxx, 020 7946 0xxx...).
|
|
136
|
+
def drama?(raw)
|
|
137
|
+
n = raw.to_s.match?(/\A0\d{9,10}\z/) ? raw.to_s : normalise(raw)
|
|
138
|
+
return false unless n
|
|
139
|
+
|
|
140
|
+
DRAMA_BLOCKS.any? do |stem, lo, hi|
|
|
141
|
+
next false unless n.start_with?(stem) && n.length == 11
|
|
142
|
+
|
|
143
|
+
tail = n[stem.length..].to_i
|
|
144
|
+
tail.between?(lo, hi)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Human-readable spacing the way UK numbers are usually written.
|
|
149
|
+
# format("07700900123") # => "07700 900123"
|
|
150
|
+
# format("+442079460123") # => "020 7946 0123"
|
|
151
|
+
# format("01144960000") # => "0114 496 0000"
|
|
152
|
+
# format("+44 7700 900123", international: true) # => "+44 7700 900123"
|
|
153
|
+
def format(raw, international: false)
|
|
154
|
+
n = normalise(raw)
|
|
155
|
+
return nil unless n
|
|
156
|
+
|
|
157
|
+
national =
|
|
158
|
+
if n.start_with?("07")
|
|
159
|
+
"#{n[0, 5]} #{n[5..]}"
|
|
160
|
+
elsif n.start_with?("02")
|
|
161
|
+
"#{n[0, 3]} #{n[3, 4]} #{n[7..]}"
|
|
162
|
+
elsif n.match?(FOUR_DIGIT_AREA)
|
|
163
|
+
"#{n[0, 4]} #{n[4, 3]} #{n[7..]}"
|
|
164
|
+
elsif n.start_with?("01")
|
|
165
|
+
"#{n[0, 5]} #{n[5..]}"
|
|
166
|
+
elsif n.start_with?("05")
|
|
167
|
+
"#{n[0, 5]} #{n[5..]}"
|
|
168
|
+
else
|
|
169
|
+
"#{n[0, 4]} #{n[4, 3]} #{n[7..]}"
|
|
170
|
+
end
|
|
171
|
+
international ? "+44 #{national[1..]}" : national
|
|
172
|
+
end
|
|
173
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: uk_sms_range
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- CryptoeSIM
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: 'Offline UK phone number helper: parses +44/0044/(0) formats, spaces
|
|
13
|
+
numbers the UK way, flags Ofcom drama/test numbers, and tells you whether a number''s
|
|
14
|
+
range normally receives SMS verification codes.'
|
|
15
|
+
email:
|
|
16
|
+
- moilyastrash+rubygems-cryptoesim@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- LICENSE.txt
|
|
22
|
+
- README.md
|
|
23
|
+
- lib/uk_sms_range.rb
|
|
24
|
+
- lib/uk_sms_range/version.rb
|
|
25
|
+
homepage: https://cryptoesim.io/blog/uk-mobile-number-format
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
documentation_uri: https://www.rubydoc.info/gems/uk_sms_range
|
|
30
|
+
rubygems_mfa_required: 'false'
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '2.7'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.6.7
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Normalise, format and classify UK phone numbers by Ofcom range (mobile, VoIP,
|
|
48
|
+
070, landline) and check if SMS codes are likely to arrive.
|
|
49
|
+
test_files: []
|