Skip to content

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.

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.

  • A Swedish national-form example with SE and its +46 form produced the same E.164 representation. A +47 example parsed as Norwegian even when the supplied context was SE (the experiment parses + independently).
  • The national string 91234567 parsed as valid under both NO and SE, but produced different E.164 destinations. Explicit context is necessary and does not prove that the user chose the intended country.
  • Phonelib.parse accepted 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 parsed 0046701234567 as a +46 number. Google’s FAQ says 00 is not an international prefix in every region, including the US. The candidate therefore rejects leading 00 after removing formatting characters; this is a conservative spike choice, not a final decision. Supporting 00 requires 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.

From the repository root, with the development web container running:

Terminal window
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.

  • 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.