Skip to content

Instantly share code, notes, and snippets.

@danishiqbal4
Created April 18, 2021 11:05
Show Gist options
  • Save danishiqbal4/9b65e79cbb4bdc9530b0dced075647d3 to your computer and use it in GitHub Desktop.
Save danishiqbal4/9b65e79cbb4bdc9530b0dced075647d3 to your computer and use it in GitHub Desktop.
IntlTelInput Init
$(document).ready(function()
{
var input = document.querySelector("#phoneNumber");
var iti = window.intlTelInput(input, {
utilsScript:'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.0/js/utils.js',
initialCountry:"auto",
separateDialCode:true,
dropdownContainer:null,
geoIpLookup: function (callback) {
$.get({url:"https://ipinfo.io",cache:true}, function () {}, "jsonp").always(function (resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
this.country+=resp.country;
callback(countryCode);
});
}
});
var handleChange = function() {
//HERE YOU CAN GET THE MOBILE NUMBER
console.log(iti.getNumber());
}
input.addEventListener('change', handleChange);
input.addEventListener('keyup', handleChange);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment