How to format a phone number using PhoneNumberUtils?

前端 未结 8 1922
慢半拍i
慢半拍i 2020-12-07 22:05

How can I format a phone number using PhoneNumberUtils?

E.g.: 1234567890(123) 456-7890

8条回答
  •  孤街浪徒
    2020-12-07 22:53

    At its most basic:

    String formattedNumber = PhoneNumberUtils.formatNumber(unformattedNumber);
    

    This will automatically format the number according to the rules for the country the number is from.

    You can also format Editable text in-place using:

    PhoneNumberUtils.formatNumber(Editable text, int defaultFormattingType);
    

    Take a look at PhoneNumberUtils for more options.

提交回复
热议问题