我正在尝试将以前E164格式的电话号码格式化为不带国家前缀号码的国家格式,我正在使用PhoneNumberUtils来完成此操作:
public static String getNationalPhone(String phoneE164Formatted) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
String phoneNumber = phoneE164Formatted;
try {
Phonenumber.PhoneNumber numberProto = phoneUtil.parseAndKeepRawInput(phoneE164Formatted, "");
phoneNumber = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
} catch (NumberParseException e) {
e.printStackTrace();
}
return phoneNumber;
}有了这个代码,我得到了我不想要的国家前缀。例如,将这个数字"+526143342293“格式化为国家格式,得到的结果是:”016143342293“,其中的"01”是我想要取消的内容。
发布于 2017-04-07 20:29:49
https://github.com/brick/phonenumber/blob/master/src/PhoneNumber.php
这些答案在php中,你可以转换成你自己的。
public function getCountryCode()
{
return (string) $this->phoneNumber->getCountryCode();
}转换上述代码将获得所需格式的国家号码。
https://stackoverflow.com/questions/41797081
复制相似问题