Click here to Skip to main content
15,946,342 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i am binding the international phone to textbox but, the flag in not showing with control, i am binding the full phone number with country code, but the text get changed the country code with 0, please help what i am doing wrong.



thanks in advance.

What I have tried:

IntlPhoneNumber(inputCtrlId) {
        
            const input = document.querySelector(inputCtrlId);
            const phoneInput = window.intlTelInput(input, {
                initialCountry: "auto",
                strictMode: true,
                nationalMode: true,
                geoIpLookup: callback => {
                    fetch("https://ipapi.co/json")
                        .then(res => res.json())
                        .then(data => callback(data.country_code))
                        .catch(() => callback("us"));
                },
                utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@19.5.3/build/js/utils.js" // just for formatting/placeholders etc
            });
            return phoneInput;


<input type="tel" id="PhoneNumber" placeholder="Enter Phone Number" required />


$("#btn1").on("click",function(){
$("#PhoneNumber").val(IntlPhoneNumber("#PhoneNumber").getNumber());
$("#PhoneNumber").val("+913333333333");

});
Posted

1 solution

You appear to be calling getNumber in your code. If you have a string that can't represented by a number, you won't get back what you think you should be getting back. Just return the string value directly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900