Phone normalization spike
Status: isolated experiment, not an application service or an approved production policy. The application Gemfile, forms, existing data and dispatch behavior are unchanged. The experiment uses synthetic strings only.
Candidate
Section titled “Candidate”phonelib 0.11.0, tested with Ruby 3.3 in the development container. It uses
Google libphonenumber data, but its Ruby implementation is not the upstream
library itself and does not implement all upstream behavior. It has an MIT
license. Compare behavior and maintenance before adopting it.
The isolated test
contains a small candidate input guard for experimentation only. It does not
establish production validation or a stable interface. Its use of
Phonelib.phone_data for checking regions is an internal API and requires a
supported alternative or explicit ownership before adoption. The test pins the
library separately from the app; do not call this code from product or Core.
Observed with this version
Section titled “Observed with this version”- A Swedish national-form example with
SEand its+46form produced the same E.164 representation. A+47example parsed as Norwegian even when the supplied context wasSE(the experiment parses+independently). - The national string
91234567parsed as valid under bothNOandSE, but produced different E.164 destinations. Explicit context is necessary and does not prove that the user chose the intended country. Phonelib.parseaccepted leading text in a sample input. An application must define and validate its complete accepted input rather than rely on parsing alone. The candidate rejects letters, extensions, semicolons and slashes; whether these should be supported is still a product decision.- With region
US, this version parsed0046701234567as a+46number. Google’s FAQ says00is not an international prefix in every region, including the US. The candidate therefore rejects leading00after removing formatting characters; this is a conservative spike choice, not a final decision. Supporting00requires explicit region-specific rules and tests. - A valid range or mobile classification is not proof of number ownership, reachability or SMS delivery. Metadata can lag numbering-plan changes and needs an update and regression-testing process.
Run the experiment
Section titled “Run the experiment”From the repository root, with the development web container running:
docker compose exec -T web sh -c 'BUNDLE_GEMFILE=/app/test/spikes/phone_normalization/Gemfile BUNDLE_PATH=/tmp/notifi-phone-spike-bundle bundle install'docker compose exec -T web sh -c 'BUNDLE_GEMFILE=/app/test/spikes/phone_normalization/Gemfile BUNDLE_PATH=/tmp/notifi-phone-spike-bundle bundle exec ruby /app/test/spikes/phone_normalization/experiment.rb'This writes the experiment’s installed gems under /tmp inside the container,
not the application’s bundle. The separate lockfile pins the experiment.
Before product integration
Section titled “Before product integration”- Choose UX for a visible, changeable number-country; distinguish that from the
physical location country and the number’s explicit
+calling code. - Decide which input forms and number types are supported, including
00, extensions, Unicode numerals, fixed line and service numbers. Do not equate library classification with SMS capability. - Decide how to handle existing national-format records without recorded region; never silently infer a destination for them.
- Choose when to validate, how to preserve original number and context, and how to present errors without logging contact data.
- Define the channel-owned normalization interface, metadata/version storage, upgrade and regression tests, then test the exact dependency in the app image.