libphonenumber将字符串转换为不带区域代码的phoneNumber [英] libphonenumber convert a string to phoneNumber without region code

查看:444
本文介绍了libphonenumber将字符串转换为不带区域代码的phoneNumber的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下内容:



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;
        }



我的问题是我只有一个电话号码作为字符串...我没有区域代码既不是国家代码也不是我需要将字符串数转换为类型phoneNumber,我不能使用Parse函数,因为它需要一个区域代码...



任何想法我怎么能这样做?


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?

推荐答案

在解析时只需用电话号码附加你的contry代码...

我不确定你的班级PhoneNumberUtil ,但这是一个简单的技巧,我希望工作得很好。



尝试使用这样的工具。

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, "");


这篇关于libphonenumber将字符串转换为不带区域代码的phoneNumber的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆