How to populate a phone number(E164)when the territory selector is chosen from the drop down list

Community Alums
Not applicable

How to populate a phone number based on the territory selector choice list Exampe: If the phone number is 13126266799 then North America needs to populated in the selector choice list same like if the phone number is +1 613-800-6513 then Canada needs to populated.

Anyone please help me on this.

8 REPLIES 8

-O-
Kilo Patron
Kilo Patron

If the ability to test is only needed on the client side, perhaps use google-libphonenumber?

Once loaded into the browser one can obtain the country code of a phone no. by executing:

var libphn = libphonenumber.PhoneNumberUtil.getInstance();
var no_1 = libphn.parse('+13126266799');
var no_2 = libphn.parse('+1 613-800-6513');
var countryCode_1 = libphn.getRegionCodeForNumber(no_1);
var countryCode_2 = libphn.getRegionCodeForNumber(no_2);
alert(countryCode_1 + '\n' + countryCode_2);

which will show the prompt:

find_real_file.png

Using this information (the obtained country code, US, CA or anything else) and making a GlideAjax call you can find out which is the country and you can set the value of the choice list.

Of course one needs to 1st normalize the entered phone no. because unless the phone number does contain the international format, the above code will not work. I mean it is logical too: how to obtain country information if the number does not contain it?

So using 13126266799 (without the international call sign of + or 00) the above code will fail when calling getRegionCodeForNumber.

While there is a phone region database in SN, it does not distinguish between US and Canada. Those are treated as a unity as North America.

SAI VENKATESH
Tera Sage
Tera Sage

Hi ,

You can write client Script .

Condition will be like : 

 for Example : if mobile number starts with +91 you can populate "INDIA "

Like wise you can do for your requirements.

 

Thanks and Regards

Sure Sai Venkatesh

Community Alums
Not applicable

Hi Sai Venkatesh,

I need to set a phone number based on the country is selected. If the country is Australia then the phone number is +61 8 7150 1149.So If I select Canada in the territory selector choice list then the phone number needs to be populated as +1 780 666 0144.

Country  
Australia +61 8 7150 1149
Brazil +55 21 3958 7888
Canada +1 780 666 0144
China +86 10 8783 3177
Colombia +57 60 2620 7388
Czech Republic +420 5 3889 0161
France +33 1 8699 5831
Germany +49 69 7104 9922
Ireland +353 6 163 9031
Italy +39 069 480 6488
Japan +81 363 628 317
Mexico +52 558 659 6002
Netherlands +31 707 006 526
South Africa +27 87 551 7702
Switzerland +41 44 529 92 72
United Kingdom +44 330 088 5830
United States +1 312 626 6799

This is the exact opposite of your original post. So what do you need:

  1. People select a country and the phone number should be filled in in another field or
  2. People enter a phone number and the country should be filled in in another field?

Also - in case it is no. 2, is there a list from where people would be selecting a phone number or is it a free entry where people can enter any phone number?