skip to Main Content

This script allows me to pick country code when I want to write my number:

const phoneInputField = document.querySelector("#inpMobilePhone");
const phoneInput = window.intlTelInput(phoneInputField, {
    utilsScript:
        "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
    });
}

This html is my phone input and the reason type=number because when I change that to type=tel it’s allows me to write text to:

<div class="form-group">
    <input type="number" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}" style="width:168%" 
        class="form-control form-control-sm" placeholder="@localizer["MobilePhone"]" 
        id="inpMobilePhone" name="MobilePhone" required />
</div>

This is the first thing i saw i want to change this:

enter image description here

2

Answers


  1. Check the initialCountry option from the documentation of intel-tel-input library.

    Login or Signup to reply.
  2. Set the initial country selection by specifying its country code.

    const phoneInput = window.intlTelInput(phoneInputField, {
        initialCountry: "TR",
        utilsScript:
            "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search