jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React and Vue components also included.
https://intl-tel-input.com
MIT License
7.66k stars 1.95k forks source link

validation of Mexico phone number with area code "56" #966

Closed gsong1205 closed 5 years ago

gsong1205 commented 5 years ago

Steps to reproduce

  1. window.intlTelInputUtils.isValidNumber("5614285xxx", "mx")
  2. country code is 52
  3. got false I am wondering why it returned false?

Expected behaviour

should return true

Actual behaviour

returned false

Initialisation options

DTHerrera commented 3 years ago

Hello, I have the same problem, when I try to validate a number with area code 56 for Mexico (+52) I get False, but I expect a True.

isValidNumber: true, el numero es: +52552128** isValidNumber: false, el numero es: +52561746**

I used the following code:

var input = document.querySelector("#fva-mobilephone"),
output = document.querySelector("#fva-landphone");

var iti = window.intlTelInput(input, {
    initialCountry: "auto",
    preventInvalidNumbers: true,
    geoIpLookup: function(success, failure) {
        $.get("https://ipinfo.io/json?token=**********", function() {}, "jsonp").always(function(resp) {
            var countryCode = (resp && resp.country) ? resp.country : "mx";
            success(countryCode);
        });
    },
    nationalMode: false,
    autoFormat: true,
    utilsScript: "{{ url_for('static',filename='invest/js/utils.js') }}" // just for formatting/placeholders etc
});

// on blur: validate
input.addEventListener('blur', function() {
    if (input.value.trim()) {
        console.info('isValidNumber: ' + iti.isValidNumber() + ', el numero es: ' + iti.getNumber());
        if (iti.isValidNumber()) {
            $('#infocorrecta').attr('disabled', false);
        } else {
            $('#infocorrecta').attr('disabled', true);
            sendbtn.disabled = true;
            $("#fva-mobilephone").focus();
        }
    }
});

Some suggestion or help is quite appreciated.

thanks Domingo Tapia