cookbook 'uk_mobile_format', '~> 1.0.0'
uk_mobile_format (1) Versions 1.0.0 Follow0
Normalise UK phone numbers and check their Ofcom prefix before using them for SMS alerts or one-time codes
cookbook 'uk_mobile_format', '~> 1.0.0', :supermarket
knife supermarket install uk_mobile_format
knife supermarket download uk_mobile_format
uk_mobile_format
A small Chef cookbook for checking UK phone numbers before they end up in
an alerting config. It normalises whatever a person typed (07700 900123,
+44 (0)7700 900123, 0044 7700-900-123) to E.164 and tells you which
Ofcom prefix block the number is in, so a landline, a 070 forwarding
number or a premium-rate number in your on-call list is caught by the
Chef run instead of during an incident.
Why "starts with 07" is not a good enough check
The 07 block in the Ofcom National Telephone Numbering Plan is split:
| Prefix | Allocated for |
|---|---|
| 071–075, 077–079 | Standard mobile. Always 11 digits: 07xxx xxxxxx, or +44 7xxx xxxxxx
|
| 07624 | Isle of Man mobile (treated as a mobile here) |
| 070 | Personal numbering: a forwarding number, not a mobile. SMS often fails |
| 076 (except 07624) | Radiopaging |
Outside 07: 01/02 are geographic landlines, 03 non-geographic
landline-rate, 05 corporate (often VoIP), 08 freephone/special rate and
09 premium rate. None of these will reliably receive a text.
Usage
Library (recipes, custom resources, anywhere)
UkMobileFormat::UkNumber.international('07700 900123') # => "+447700900123" UkMobileFormat::UkNumber.kind('020 7946 0000') # => :geographic UkMobileFormat::UkNumber.standard_mobile?('+44 7700 900123') # => true UkMobileFormat::UkNumber.sms_reject_reason('0808 157 0000') # => "08 is freephone or special-rate" (nil means the prefix looks fine)
Inside recipes and resources the module is also available as uk_number.
Recipe uk_mobile_format::default
Checks node['uk_mobile_format']['numbers'] and logs a warning for every
number SMS will probably not reach. Set node['uk_mobile_format']['strict']
to true to fail the run instead.
default['uk_mobile_format']['numbers'] = ['07700 900123', '020 7946 0000'] default['uk_mobile_format']['strict'] = true
Resource uk_mobile_format_sms_contacts
Writes a file of E.164 numbers, one per line, for smstools, a Twilio or
Vonage notifier, or any script that sends alert texts. Numbers without a
standard mobile prefix are skipped with a warning, or fail the run with
strict true.
uk_mobile_format_sms_contacts '/etc/alerting/sms_contacts' do numbers ['07700 900123', '+44 (0)7700 900456', '0306 999 0000'] strict false mode '0640' end
What it cannot tell you
It is a format and prefix check only. It does not query a network, so it
cannot tell whether a number is in service, whether it has been ported,
or whether a mobile-looking +44 7… number is actually delivered over
VoIP. Many sign-up and verification services reject virtual numbers even
when the prefix looks right, so treat standard_mobile? as necessary, not
sufficient.
If what you need is a number rather than a validator, for example an
anonymous UK phone number to keep
your personal SIM out of app sign-ups, Ghost SIMs rents real +44 7 mobile
numbers that receive SMS verification codes into a private inbox.
Tests
ruby test/unit/uk_number_test.rb (minitest, no Chef needed). Every test
number is from Ofcom's drama ranges, which are reserved and never issued:
mobile 07700 900000–900999, London 020 7946 0000–0999,
0306 999 0xxx, 0808 157 0xxx and 0909 879 0xxx. 070 and 076 have
no drama range, so those tests use all-zero digits.
Licence
MIT. Copyright 2026 Ghost SIMs.
Dependent cookbooks
This cookbook has no specified dependencies.
Contingent cookbooks
There are no cookbooks that are contingent upon this one.
uk_mobile_format changelog
1.0.0 (2026-11-24)
- First release:
UkMobileFormat::UkNumberlibrary,defaultrecipe anduk_mobile_format_sms_contactsresource.