Is there such a thing as telephone library cleaning

I would like to find a tool / library that can enter user-entered toll-free phone numbers of the format entered through the website and analyze them for a number suitable for calls from a given country.

It is not as simple as it might seem at first glance. The website allows people around the world to enter their number in any way, so many people enter national numbers (the country is also provided in a different field). Some people enter the international number in the "correct" formats (with "+"), some people enter it a little less correctly using the prefix of their country.

I would like to tell the library / tool the country to which I am dialing the number and the phone number in free format and, possibly, the country to which this corresponds (as this will help generate the international code if it has not been entered) and it uses well-known templates, to best guess the number that will work in my calling country.

So, for example, when calling from the USA to a number in the UK:

+44 (0) 1225-344567 => 011441225344567 

Or when calling from the UK to a number in the USA:

 (613) 4562342 => 0016134562342 

Does anyone know of any (ideally .NET Framework-friendly) solutions that will avoid me, undoubtedly reinvent the wheel.

+8
c # phone-number
source share
5 answers

Yes: the general Java, C ++ and Javascript library of Google for parsing, formatting, storing and checking international phone numbers has now been ported to C #:

https://github.com/erezak/libphonenumber-csharp

Good luck

+2
source share

I did just that, Mark. I work for a wireless operator and have an international application for sending SMS. I do not know any third-party libraries that comply with these rules. As mentioned above, you cannot just deal with random input, as the formats of phone numbers vary between countries. Some countries, such as Germany, have variable-length area codes and phone numbers. If they do not put the country code, you are sunk. However, in my case, I can assume that if he lacks the country code, this is a phone number in the USA. The results of my filter turned out to be very accurate with the users and the data that I had.

You can make some assumptions, and knowing the target audience, registering the input data and analyzing, you can get the things you have collected. My first implementation was for a white-labeled web application that is used for testing by various people around the world. I quickly discovered that most foreign people act together and are used to a quasi-standard + format. Typically, Americans enter the phone numbers that are most confused. Europeans are very accustomed to international recruitment.

The first rule is to cut everything except numbers and "+".

If the resulting number contains less than 8 digits, it is inactive, report a user error.

If the resulting number starts with the '+' character, suppose that it is a standard format and that the next 2-6 digits represent the "country code". Run the country code, then process the remaining digits in accordance with the rules for that country.

If the number starts with 0, suppose that someone prefixed the international access and canceled the leading 0 and 1, and then: if the remaining number is 10 digits, suppose this is an American number entered by an American, and process accordingly. If the remaining number is not 10 digits, but not less than 8, suppose that the first 2-6 digits are the country code, look at the country code and process it in accordance with the rules of that country.

If the number starts with 1, and only 11 digits, suppose it is a number in the United States (or on the island of the Caribbean) and is processed accordingly.

If the number starts with 1 and is not equal to 11 digits, divide the leading 1s, see if at least 8 digits remain, and consider that the remaining leading digits from 2 to 6 are the country code and the process according to the country of the rule.

Finally, with a number not leading with +, 0, or 1, and at least 8 digits, suppose it is in standard notation without the + character, which is the first country code, use the first 2-6 digits as the country code and process in according to the rules of this country.

The trick in all this is to have a comparison of all country codes of the world and information on the numbering plan for each country. I have this card and the rules for many countries. If you need this information, I would be happy to share, as well as some C # code that determines which country. Tell me.

A great help with this is to send the name of the country that your software guesses to the user. They will quickly understand if they are trying to enter a German phone number, and your software will ask them if they are trying to dial Guam!

+7
source share

The Google Library library for parsing, formatting, storing and checking international phone numbers has now been ported to C #.

https://github.com/erezak/libphonenumber-csharp

+1
source share

No no. There are very few rules that govern telephone numbers between countries. Some countries even have several representations.

In the UK, for example, there are variable-sized codes, for example:

  • 0121 = Birmingham
  • 01223 = Cambridge
0
source share

There is a β€œstandard” for formatting international (and national) phone numbers. They look like this: +31 42 123 4567 (+ number prefix number). Example from Wikipedia . Although you should not expect someone to enter it that way. In my experience, users are more likely to stick to the format they are used to.

I do not know a single library that will convert between all (mostly local) views specified by me or any other format.

0
source share

All Articles