Parsing phone numbers in Node JS using libphonenumber

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

The input will be a list of phone number strings, which can take the form (given that 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 save all these numbers in an international format according to the google libphonenumber library.

  • Now, is there a way to find out (or guess) the correct country code if this is missing?

  • How do I split a country code with a phone number when it is available?

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

Thanks in advance

+4

Source: https://habr.com/ru/post/1547696/


All Articles