Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation no working with INTL-TEL-INPUT

I'm trying to use intl-tel-input... https://github.com/Bluefieldscom/intl-tel-input#utilities-script

I've included the css at the top of the sheet

<link rel="stylesheet" href="css/intlTelInput.css">

My form in the middle with "tel" id... I am also using parsley to validate parts of the form, and that is working fine,

<input class="form-control input-sm"  id="tel" name="tel" type="tel" data-parsley-required>

and at the bottom of my page i included the jquery, bootstrap, etc... and intl-tel-input js....

 <script src="js/jquery.js"></script>
 <script src="js/bootstrap.min.js"></script>
 <script src="js/parsley.js"></script>
 <script src="js/intlTelInput.min.js"></script>

And then i initialize the utility...

$("#tel").intlTelInput({
            utilsScript: "js/utils.js"
});

The form element picks up the country flags, so the plug in appears to be working, but no validation is occurring. The utils.js file is the "compiled" version of the file, which i believe is the correct one to use - but i've tried both the compiled and non compiled version.

What am i missing here? why isn't the validation and formatting working?

thanks.

like image 726
Skinner Avatar asked Apr 27 '15 02:04

Skinner


People also ask

What is INTL Tel input?

International Telephone Input It is a jQuery plugin for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods. It is also widely known as intl-tel-input.

How do you get the country code from INTL Tel input plugin after submitting the form?

attr("data-dial-code") should give you the dial code for the country that's been selected. You'll have to pass that variable manually using submit then. Or append before the string the value obtained here to the telephone number being sent to PHP.


1 Answers

For working validation you need call utils.js validation functions See below example

$("#tel").change(function()
{
  var telInput = $("#tel");
  if ($.trim(telInput.val())) 
  {
    if (telInput.intlTelInput("isValidNumber")) 
    {
      console.log(telInput.intlTelInput("getNumber"));
      alert('Valid' );
    }
    else 
    {
      console.log(telInput.intlTelInput("getValidationError"));
      alert('invalid');
    }
  }
});
like image 163
Prathmesh Avatar answered Nov 10 '22 03:11

Prathmesh