I need to make a UI that calculate the fees of communication for my entreprise.
In the DataBase I have :
*a Table that contain (Country Code : Fee per Minute)
*a Table that contain(Phone number : Duration)
I need to calculate the total fee, the problem is about detecting the country in the phone number(from worldwide), I have no standardformat for the phone number.
I will give you one example why this will never work 100% correctly. But first an introduction.
A phone number in most countries is built from three parts: the international calling code, the area code, and the subscription number. For example, +1-555-1234 has an international calling code of +1, an area code of 555 and a subscription number of 1234. You would think that using the international calling code would help you out finding the country. That's where my example comes in.
The US has international calling code +1. That makes you think that anything starting with +1 would come from the US. That's where you would think wrongly:
American Samoa uses +1-684.
Anguilla uses +1-264.
Antigua and Barbuda uses +1-268.
Bahamas uses +1-242.
Barbados uses +1-246.
Bermuda uses +1-441.
Cayman Islands uses +1-345.
Dominica uses +1-767.
Dominican Republic uses +1-809.
Grenada uses +1-473.
Guam uses +1-671.
Jamaica uses +1-876.
Montserrat uses +1-664.
Northern Mariana Islands uses +1-670.
Puerto Rico uses +1-787.
Saint Kitts and Nevis uses +1-869.
Saint Lucia uses +1-758.
Saint Vincent and the Grenadines uses +1-784.
Trinidad and Tobago uses +1-868.
Turks and Caicos Islands uses +1-649.
Virgin Islands, U.S. uses +1-340.
So now you're thinking, "but I can check for those, and there wouldn't be a problem." Unfortunately, you'd be wrong again:
United States uses +1.
United States Minor Outlying Islands uses +1.
Canada uses +1.
And there you have it - one international calling code used by three different countries.
And this page lists the area codes used by Canada.
So you could theoretically create a list for those exceptions, (and those darn exchange ones, like 555) and then everything else is "the US". But I agree, it's not ideal.
@Houssem: Fortunately, most other countries don't have the same issue; although if this is a tariff system, you may well have problems with somewhere like Russia, because its quite possible that phoning Moscow from Vladivostok is actually more expensive than phoning Tokyo or Seoul, which are a lot closer.
I suspect you have quite a lot of prep work ahead of you.
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
It uses an XML document to describe the countries. This splits the countries first per first digit which apparently can be used to distinguish the region (1 == North America, 3 and 4 == Europe, etc), then the next digit(s) to find the country. The UK for instance is +44, so is found in the region with code 4, then 4 underneath that for the UK itself. Unfortunately for you, that list fails miserably for the US and Canada.