International phone numbers support
See original GitHub issueHi @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:
- Created 6 years ago
- Reactions:4
- Comments:12 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@joshswan @joaopiopedreira Did you consider to use libphonenumber-js to detect the phone number?
Using the findPhoneNumbers method.
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.