How to extract the international dial code together with the input?

73 views Asked by At

I wanted to optimize the registration process and I have added the international dial input.

I want to extract the input together with the dial code value.(I was thinking to do a concatenation between the element value and input, but I don't know how to do that exactly)

This is my javascript function that extracts the user input, at the moment:

async function validate_phone() {
  let phone = $('input[rel="phone"]').val();
  let pattern = /^\+?[0-9]{6,17}$/;
   if (!pattern.test(phone)) {
      alert('<%= l("Invalid phone number") %>');
   } else {
      await fetch(`/phone/${phone}/in-use`).then(response => {
      return response.json();
      }).then(data => {
         taken_phone = data.taken;
   });
   if (taken_phone == 1) {
   $('#phone-check-taken').show();
   alert('<%= l("Phone number already in use.") %>');
   } else {
    $('#phone-check-taken').hide();
    ++step;
   }
 }
}

enter image description here

0

There are 0 answers