Git Product home page Git Product logo

Comments (4)

twcclegg avatar twcclegg commented on July 28, 2024

After some digging those numbers appear to be from Inmarsat and South Sudan respectively. All numbers, in order to parse need to be either in E164 format (+870773924761, +211912378429), or have their region code provided. For South Sudan "SS", for Inmaset I can find reference to one but "GB" works.

from libphonenumber-csharp.

Ketan-Desai avatar Ketan-Desai commented on July 28, 2024

Hi Tom,

As I understand, the specified numbers are in E164 format.
So without specifying region code, it can be parsed.

But it throws an exception on my side.

Here is the code snippet, please advise if it needs any correction...

        public static bool TryParse(string s, out Number number)
        {
            number = null;

            //if (s == null || !s.All(char.IsDigit))
            //    return false;

            s = "+" + s.Substring(2);

            var phoneNumberUtil = PhoneNumberUtil.GetInstance();

            if (phoneNumberUtil.IsPossibleNumber(s, null))
            {
                var phoneNumber = phoneNumberUtil.Parse(s, null);

                if (phoneNumberUtil.IsValidNumber(phoneNumber))
                {
                    string regionCode = phoneNumberUtil.GetRegionCodeForNumber(phoneNumber);

                    // +870773924761 Region Code = '001'
                    if (InternationalNumberManager.RegionCountryNameDictionary.TryGetValue(regionCode, out string region))
                    {
                        string desc;

                        // +211912378429 Exception
                        try
                        {
                            string cityState = PhoneNumberOfflineGeocoder.GetInstance().GetDescriptionForValidNumber(phoneNumber, Locale.English);

                            desc = ((cityState == region) ? cityState : cityState + ", " + region) + " (International)";
                        }
                        catch
                        {
                            desc = region + " (International)";
                        }

                        number = new InternationalNumber { Code = phoneNumber.CountryCode, Description = desc };

                        return true;
                    }
                }
            }

            return false;
        }

The input is like 00870773924761, 00211912378429, etc...
InternationalNumberManager.RegionCountryNameDictionary is Dictionary<string, string> type.

Thanks

from libphonenumber-csharp.

twcclegg avatar twcclegg commented on July 28, 2024

Copying your code above, of the few numbers I've tried nothing throws an exception. It returns false if the region code isn't in the dictionary. The first number returns a region code of "001" (quite the curious number you've selected), the second "SS", as long as both of these are in the dictionary both work without error and return true for me.

from libphonenumber-csharp.

Ketan-Desai avatar Ketan-Desai commented on July 28, 2024

Hi Tom,

Thanks for verifying the code and numbers.

Why there is an issue with 00211912378429 number.
The try/catch block is added for it specifically.

Thanks

from libphonenumber-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.