Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the full number using intlTelInput

I am using the demo code for intlTelInput provided here

I am able to get the dial code using following

var intlNumber = $("#phone").intlTelInput("getSelectedCountryData");

But i am not able to get the full number i.e. "dialcode + number entered by user" from the #phone text box.

like image 259
Sachin Pakale Avatar asked Oct 10 '17 10:10

Sachin Pakale


People also ask

How do I get intlTelInput value?

You can use intlTelInput('getSelectedCountryData'). dialCode to get country code selected from dropdown. stackoverflow.com/questions/46664571/… Thanks, I found the answer in this.

How do you get the country code from INTL Tel input plugin after submitting the form?

country[class*='active']"). attr("data-dial-code") should give you the dial code for the country that's been selected. You'll have to pass that variable manually using submit then. Or append before the string the value obtained here to the telephone number being sent to PHP.


2 Answers

Use the getnumber option, so in your case:

var intlNumber = $("#phone").intlTelInput("getNumber");

^ This will give you the entire number (country code + phone number)

See docs here.

like image 153
Khaled Avatar answered Oct 17 '22 21:10

Khaled


You have to use the built-in methods for getting the full number but you must add the utilsScript

 $("#phone").intlTelInput(
    { 
      //Other configurations,
      //Other configurations,
      utilsScript : "/path/to/build/utils.js",

    });

in the initialization for the intlTelInput as stated here Intl-Tel-Phone Docs

and then you can get the full number by using

$("#YourInputElementID").intlTelInput("getNumber");
like image 33
Nafiu Lawal Avatar answered Oct 17 '22 22:10

Nafiu Lawal