1

I want to validate mobile number worldwide,so i have search a lot and finally get intl-tel-input library to perform this task easily.

i m using this from GitHub, all thing work fine.

Problem is that i m not getting auto Country Code based on user ip address in my project but when i use it individually it works.

i m sharing all thing that i have done.

i m working on

-MVC Asp

Here is the screenshot that i actually want.

https://i.stack.imgur.com/1y8G8.jpg

Here is the screenshot that i got yet

https://i.stack.imgur.com/b6F01.jpg

Error i got

Firefox

The script from “https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More] Register Loading failed for the with source “https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068”. Register:1:1

https://i.stack.imgur.com/sTQsZ.jpg

Chrome

GET https://ipinfo.io/?callback=jQuery112403105878441128118_1555701843619&_=1555701843620 net::ERR_ABORTED 429

https://i.stack.imgur.com/vyw6Y.jpg

Here is some code that i used

View

@Html.EditorFor(model => model.user_mobile, new { htmlAttributes = new { @class = "form-control", id = "mobile" } })

Scripts

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="~/js/bootstrap.min.js"></script>

<!-- Multi select -->
<script src="~/js/multi_select.js"></script>

<!-- Select 2-->
<script src="~/js/select2/select2.full.min.js"></script>



<!-- Custom JS File -->
<script src="~/js/custom.js"></script>

<script src="~/Scripts/validation/phone/intlTelInput.js"></script>
<script type="text/javascript">

    var input = document.querySelector("#mobile");
    window.intlTelInput(input, {
        initialCountry: "auto",
        geoIpLookup: function (callback) {
            $.get('https://ipinfo.io', function () { }, "jsonp").always(function (resp) {
                var countryCode = (resp && resp.country) ? resp.country : "";
                callback(countryCode);
            });
        },
        //utilsScript: "build/js/utils.js" // just for formatting/placeholders etc
    });

    $(function () {
        $('.multiselect-ui').multiselect({
            includeSelectAllOption: true
        });
    });

    // Select 2 searchable
    $(function () {
        //Initialize Select2 Elements
        $('.select2').select2()
    });





</script>

Help me out to solve my problem

i want to get auto country code based on user ip address

Ramzan
  • 15
  • 6

1 Answers1

0

You need to replace url with token: be like: https://ipinfo.io -> https://ipinfo.io?token=$Your_token

You need to register at https://ipinfo.io/ at get your token.

Kon Smart
  • 1
  • 1
  • 2