How to check if the user entered the phone number by the country code?

Is there an easy way to check if a user phone number, country code has been entered and check the number is correct? I do not use any specific formats, the number itself should be only digits, no ('s, - etc. Is this confirmation possible without user request for the country? The trick is that I want to work with all worlds of numbers by to the whole world.

I think this cannot be done with regex (a bit distorted and many things found, but not for this problem). Is there a library for this? I am using python.

Or maybe it would be more appropriate to apply the format, for example. X-YYYYYYYY ... where is X the country code or something like that?

+5
source share
3 answers

I studied this topic for a while. We have a huge database with numbers, no one knows if they have a contract code or not. General answer: it is impossible to find out. We had some numbers that were valid US numbers without a country code (1) and valid numbers of some other countries with a regional code. But for 99% of cases, you can check if the length of the number is 9, then there is no code. You must enforce users to enter the contract code.

+1
source

Google ( Java). , Google Python, , Python, -, , , .

+4

, 247 8000, :

  • 247 8000 , , +1 212 247 8000
  • 8000 247 , , +269 247 8000
  • 8000 247, +247 8000

.

+ .

+2

All Articles