4

I need to parse all the phone numbers extracted from my phonebook to lets say a flat file

The input will be a list of phone number strings which can be of the form (considering my location is India)

+91-99XXXXXXXX
98XXXXXXXX
098XXXXXXXX
011-25XXXXXX     // This is a Delhi local number
0044-79XXXXXXXX  // A number from England
+1-602-XXXXXXX   // A number from US
602-XXXXXXX      // Another number from US but missing country code
2582XXXX         // A local number from Delhi but missing state STD code of 011

Now I need to store all these numbers in International format as per the libphonenumber library of google.

  • Now, is there any way to know (or guess) the correct country code if it is missing ?

  • How do I split the country code from phone number when it's available ?

  • And so far from what I have seen in the google's libphonenumber library, it takes input as phone number and ISO country code to parse a phone number. But how do I get the ISO country code from the numeric ISD code ?

Thanks in advance

Mandeep Singh
  • 7,674
  • 19
  • 62
  • 104
  • Did you figure this out? Would appreciatie it if you could share! – bdv Dec 08 '15 at 15:17
  • 1
    Yes, kind of. Sending the ISO is mandatory in the libphonenumber parser. The number that you send along, can be in the local format or international format. However, if the format is local (without ISD code), the library assumes that the number belongs to the country for which you specify the ISO. for example I can send ISO as 'IN' and number as '01125991212'. And since the number is a valid phone number in India, it will successfully parse. However, if I pass a US phone number without the +1 prefix and send the ISO as 'IN', I will not be able to get a valid number from the libary – Mandeep Singh Dec 08 '15 at 18:45

0 Answers0