0

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

Neeraj Kumar
  • 771
  • 2
  • 16
  • 37
  • You need to implement 2 parts, 1st is to get the country iso code from IP address using any geolocation data, for example, https://lite.ip2location.com or https://www.ipinfodb.com. 2nd is to get the IDD dial code, the list can be retrieved from this thread https://stackoverflow.com/questions/10772329/how-to-get-country-phone-prefix-from-iso – Chris Lim Nov 14 '17 at 02:56

1 Answers1

2

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/

Oswaldo
  • 39
  • 4