Giter VIP home page Giter VIP logo

Comments (2)

som3apf avatar som3apf commented on June 4, 2024

also, for dial_code, it is showing without the "+", and getNumber is showing everything with the code. is there a way to separate them with jquery? or is there a way to get them specifically? updated code below

Thank you in advance


$(document).ready(function() {
var telInput = $("form input.form-input:eq(2)");
telInput.attr('type', 'tel');
telInput.css('width', '100%');

telInput.intlTelInput({
nationalMode: false,
preferredCountries: ["ae", "us", "gb"],
utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/10.0.7/js/utils.js"
});

// Example: Extract data when form is submitted
$("form").on("submit", function(event) {
event.preventDefault(); // Prevent form submission for this example

var isValid = telInput.intlTelInput("isValidNumber");
console.log("isValid: " + isValid);

if (isValid) {
  var selectedCountryData = telInput.intlTelInput("getSelectedCountryData");
  console.log("Selected Country Data: " + selectedCountryData);

  var dial_code = selectedCountryData.dialCode;
  console.log("Country Dial Code: " + dial_code);

  var number_without_dial_code = telInput.intlTelInput("getNumber");
  console.log("Phone Number: " + number_without_dial_code);

  // var HiddenCountryCodeField = document.getElementById("field-667e708bbbbafc1e5d1a062ee006ddf7-8");
  $("#field-667e708bbbbafc1e5d1a062ee006ddf7-8").val("+" + dial_code);

  // var HiddenPhonNumberField = document.getElementById("field-667e708bbbbafc1e5d1a062ee006ddf7-9");
  var HiddenPhonNumberField = $("#field-667e708bbbbafc1e5d1a062ee006ddf7-9");
  HiddenPhonNumberField.val(number_without_dial_code.replace("+" + dial_code, "").trim());
} else {
  telInput.val('');
  console.log("Invalid phone number");
}

});
});

from intl-tel-input.

jackocnr avatar jackocnr commented on June 4, 2024

If you want to get the national number (without international dial code), you can pass intlTelInputUtils.numberFormat.NATIONAL as an argument to getNumber (see the readme for more info)

from intl-tel-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.