How to format a phone numbers with libphonenumber

2019-03-26 12:14发布

In the documentation provided by libphonenumber on Github, there is a demo, which converts any provided number into International Format, e.g +4915213116250 is converted into +49 1521 3116250

I want to use the same functionality in C#.

In the documentation of libphone, there is need to parse the number and provide the countries/regions. But the demo works without providing the region/country. Can some body let me know how it is done?

1条回答
神经病院院长
2楼-- · 2019-03-26 13:13

Have you tried this?

var phoneUtil = PhoneNumberUtil.GetInstance();
var numberProto = phoneUtil.Parse("1234567890", "IT");
var formattedPhone = phoneUtil.Format(numberProto, PhoneNumberFormat.INTERNATIONAL);

This will give you "+39 123 456 7890"

查看更多
登录 后发表回答