Neeraj Kumar
Neeraj Kumar

Reputation: 779

How do I add default (Default to browser country) country code before the mobile number in MVC ASP.NET?

I have got a Textbox accepting mobile number. How do I add default (Default to browser country) country code before the mobile number?

I am using MVC ASP.NET

Upvotes: 0

Views: 592

Answers (1)

Oswaldo
Oswaldo

Reputation: 39

You can use the service, http://ipinfo.io, to detect the country by user's IP (The location will generally be less accurate than the native geolocation details, but it doesn't require any user permission). It will give you the client IP, hostname, geolocation information (city, region, country, area code, zip code etc) and network owner.

$.get("https://ipinfo.io", function(response) {
   console.log(response.city, response.country);
}, "jsonp");

Here's a more detailed JSFiddle example that also prints out the full response information, so you can see all of the available details: http://jsfiddle.net/zK5FN/2/

Upvotes: 2

Related Questions