How to format a phone numbers with libphonenumber in International format.

让人想犯罪 __ 提交于 2019-12-04 18:39: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:


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"



来源:https://stackoverflow.com/questions/31611446/how-to-format-a-phone-numbers-with-libphonenumber-in-international-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!