Click here to Skip to main content
15,071,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm using the below:

bool isSuccess = false;
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();

      PhoneNumber numberProto = phoneUtil.Parse(phoneNumber, "");
      var regionCode = phoneUtil.GetRegionCodeForNumber(numberProto);

      bool isValid = phoneUtil.IsValidNumber(numberProto);

      var cc = phoneUtil.GetCountryCodeForRegion(regionCode);
        var number = phoneUtil.ParseAndKeepRawInput(phoneNumber, regionCode);

        var b = phoneUtil.GetNumberType(number);

        if (b == PhoneNumberType.MOBILE)
           isSuccess= true;

my problem is that i have only a phone number as a string... i don't have a region code neither a country code and i need to convert the string number to type phoneNumber, i can't use the function Parse because it needs a region code...

any ideas how can i do that?
ZurdoDev 16-May-14 9:37am
Where are you stuck? It sounds like you are using some class I have never heard of, PhoneNumberUtil. Is this a google thing? If so, I would start by asking there.
KaushalJB 16-May-14 9:40am
Jocelyne did u try using
Convert.Tostring() or Convert.ToInt32() ?

1 solution

Just append your contry code with Phone Number while parsing...
I'm not sure of your class "PhoneNumberUtil", But It's a Simple trick which I hope to be work good.

Try using like this.
PhoneNumber numberProto = phoneUtil.Parse("+91" + phoneNumber, "");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900