I am using libphonenumber-csharp and when I make the following call:
PhoneNumberUtil = PhoneNumberUtil.GetInstance();
var phoneNumber = PhoneNumberUtil.Parse(e164PhoneNumber, null);
return PhoneNumberUtil.Format(phoneNumber, PhoneNumberFormat.INTERNATIONAL);
I get "+1 303-123-4567". How can I instead get "+1 (303) 123-4567"?
Is my best bet to use regular expressions and if it's "+1 ###-###-####" then adjust it? I think that would be safe as the +1 tells me it's U.S.
Here's what I did. It works. And it uses the libphonenumber returned string if it's not exactly "+1 303-123-4567..." and so should be safe. Keep in mind this does not need to handle all possible phone formats. It only needs to handle the format libphonenumber returns.