-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Description
Country code not appended on some iOS Safari devices – intl-tel-input
fails to include dial code in submitted value
Description
We are facing an issue where the country code is not being appended to the phone number input on some iOS devices with Safari browser when using intl-tel-input
.
Working Example
When the country code is correctly appended:

Failing Example
When the country code is missing (only local number submitted):


Steps to Reproduce
- Open our signup form with
intl-tel-input
on iOS Safari. - Select a country or rely on auto-detection.
- Enter a valid phone number.
- Submit the form.
Expected Result
window.iti.getNumber()
should return the full number with country code (e.g., +919876543210
).
Actual Result
window.iti.getNumber()
sometimes only returns the local number (e.g., 9876543210
), missing the country code entirely.
Code Snippet
Here’s how we initialize intl-tel-input
in our form:
<script>
document.addEventListener("DOMContentLoaded", function () {
const input = document.querySelector("input[ms-code-phone-number]");
const continueBtn = document.getElementById("continue-btn");
if (!input) return;
const preferredCountries =
input.getAttribute("ms-code-phone-number")?.split(",") || [];
window.iti = window.intlTelInput(input, {
preferredCountries,
separateDialCode: true,
utilsScript:
"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.8/js/utils.js",
customContainer: "max-width-full",
});
fetch("https://ipinfo.io/json")
.then((response) => response.json())
.then((data) => {
window.iti.setCountry(data.country);
})
.catch(console.error);
input.addEventListener("input", () => {
const isValid = window.iti.isValidNumber();
if (continueBtn) continueBtn.disabled = !isValid;
});
const form = document.getElementById("signup-form");
form?.addEventListener("submit", async function (e) {
e.preventDefault();
if (isProcessingContinue) return;
isProcessingContinue = true;
const originalBtnText = continueBtn.textContent;
continueBtn.innerHTML = '<span class="loading-spinner"></span>Continue';
continueBtn.disabled = true;
const phoneNumber = window.iti.getNumber();
const countryData = window.iti.getSelectedCountryData();
const countryCode = countryData.dialCode;
const actualPhoneNumber = phoneNumber.substring(countryCode.length + 1);
window.phoneNumberForOTP = phoneNumber;
if (!phoneNumber) {
isProcessingContinue = false;
continueBtn.innerHTML = originalBtnText;
continueBtn.disabled = false;
return;
}
localStorage.setItem("phone_number", phoneNumber);
try {
const initiate = await hitOTPlessSdk({
requestType: "initiate",
request: {
channel: "PHONE",
phone: actualPhoneNumber,
countryCode: `+${countryCode}`,
deliveryChannel: "WHATSAPP",
otpLength: 6,
expiry: "120",
},
});
if (initiate.success) {
const phoneEvent = new CustomEvent("phoneUpdate", {
detail: phoneNumber,
});
window.dispatchEvent(phoneEvent);
document.getElementById("phone-section").style.display = "none";
document.getElementById("otp-section").style.display = "block";
} else {
showError(initiate.message || "Failed to send OTP");
continueBtn.innerHTML = originalBtnText;
continueBtn.disabled = false;
}
} catch (error) {
console.error("Error:", error);
showError("Error sending OTP");
continueBtn.innerHTML = originalBtnText;
continueBtn.disabled = false;
} finally {
isProcessingContinue = false;
}
});
});
</script>
Additional Notes :
- This issue happens only on iOS Safari (and sometimes in-app browsers using WebKit).
- It seems that iti.getNumber() does not always recompute the full international number after input is typed.
- Works fine on Android Chrome.
- Would appreciate guidance on how to ensure getNumber() reliably includes country code before form submission.
Metadata
Metadata
Assignees
Labels
No labels