question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

International phone numbers support

See original GitHub issue

Hi @joshswan , it looks like we can override the phone regex directly in your src/matchers.js file. I’ve done it in my branch and it works like a charm. The idea is to add a regex by country and then merge them all when invoking the phone autolinker.

To add a new country, we would add the corresponding regex to this object (in src/matchers.js):

// To include a new country, find it's ISO Alpha 2 code at http://www.nationsonline.org/oneworld/country_code_list.htm
const regexByCountry = {
  US: /(\([0-9]{3}\)[\s-]|[0-9]{3}[\s-])[0-9]{3}[-\s][0-9]{4}/g,
  GB: /(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)?(44)\)?[\s-]?(? (...),
  FR: /(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)?(44)\)?[\s-]?(? (...),
  PT: /(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)?(44)\)?[\s-]?(? (...),
  IE:  /(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)?(44)\)?[\s-]?(? (...),
  DE:  /(?:(?:\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)?(44)\)?[\s-]?(? (...),
};

Our phone override would then look like this:

  // Phone override
  {
    id: 'phone',
    regex: combinedRegex(['US', 'GB', 'FR', 'PT', 'IE', 'DE']),
    Match: Autolinker.Util.extend(Autolinker.match.Match, {
      constructor(cfg) {
        Autolinker.match.Match.prototype.constructor.call(this, cfg);
        this.number = cfg.phone;
      },
      getType() {
        return 'phone';
      },
      getNumber() {
        return this.number;
      },
      getAnchorHref() {
        return `tel:${this.number}`;
      },
      getAnchorText() {
        return this.matchedText;
      },
    }),
  },

Is this something you’d want to include in your package? Should I submit a PR? Cheers

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
StevenMasinicommented, Jul 3, 2018

@joshswan @joaopiopedreira Did you consider to use libphonenumber-js to detect the phone number?

Using the findPhoneNumbers method.

1reaction
joshswancommented, Jul 3, 2018

Yep the issue lies in Autolinker.js. I’ll take a look at the findPhoneNumbers method though since that could be much easier than having country by country regexes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Customer Service phone numbers - Microsoft Support
Curaçao. +1. 00 1 866 543 2085 305 418 9136 (International). Nederlands / English / Español ; Dominica. N/A +1. 1 866 993...
Read more >
International phone number support | Login.gov
Country Dialing Code Supports SMS Supports Voice Afghanistan (AF) +93 No No Albania (AL) +355 Yes No Algeria (DZ) +213 No No
Read more >
International Support Phone Numbers | NETSCOUT
International Support Phone Numbers ; Mexico, 01 800 123 0134 ; Netherlands, +31 (0) 707 709470 ; New Zealand, 442070268403 ; Norway, +47...
Read more >
International Toll Free Number - TollFreeForwarding.com
An international toll free number (ITFN) is a number that your customers can call at no charge to them. Calls can be placed...
Read more >
International Phone Numbers - Western Digital
Reach out to our support team and we'll get back to you as soon as possible. Submit a case.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found