Add support for international phone number format

Created on 29 August 2023, about 1 year ago

Problem/Motivation

As stated on the project page, the module currently supports US 10 digit telephone numbers like (234) 456-7890. International phone number format starts with a plus sign (+) followed by the country and city codes, and the local number (like +1 234 456 7890).

Currently numbers in international format are "forced" into the 10-digit system, For example, this

<a href="tel:+1 234 456 7890">+1 234 456 7890</a>

becomes

<a href="tel:2344567890">(234) 456-7890</a>

It would make the module usable internationally to accept international phone number format.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany yan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @yan
  • πŸ‡©πŸ‡ͺGermany yan

    I just realized that this is probably more complicated than I thought because the E.164 standard for international phone numbers can have country codes of variable length (for example +1 for the US and Canada, +49 for Germany, +233 for Ghana etc.). Also city codes vary a lot.

    Google's libphonenumber could come to the rescue, but it's probably an overkill in most use cases (> 200kb minified code). But it might be an option that could be activated. More on the topic here.

    Another way could be to define a format in the module settings (for example telling how to slice the numbers).

    In my case, for a German phone number (+49) I just patched phoney.js in lines 89 and 90 to this:

    element.setAttribute('href', 'tel:' + tel);
    element.innerHTML = '(' + tel.slice(0,3) + ') ' + tel.slice(3,6) + '-' + tel.slice(6);

    Not a solution, but a workaround to display a German number with a 3-digit mobile code like this: +49 123 4737628.

  • πŸ‡ΊπŸ‡ΈUnited States bkelly

    Hi @yan -

    Perfect, glad you could extend it to meet your needs, (the beauty of open source).

    I agree, the various international formats make it a minefield of issues that I really can't support.

    I wrote the module for personal use but wanted to offer it to anybody with similar privacy concerns. However I don't really have the time/energy to support an international version and intentionally limited the scope. Plus, I'm really not much of a JavaScript coder.

    Thank you for your time.

    -- Bill Kelly

  • Status changed to Closed: works as designed about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States bkelly
Production build 0.71.5 2024