首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使libphonenumber格式化法语电话号码?

如何使libphonenumber格式化法语电话号码?
EN

Stack Overflow用户
提问于 2018-04-13 01:13:55
回答 1查看 801关注 0票数 0

我正在查看libphonenumber库(https://github.com/googlei18n/libphonenumber),但我只能让它在"US“和"BR”区域工作。我如何让它在"FR“地区工作?我正在寻找的格式是14022500。

我能够用我自己的代码获得这种格式。

代码语言:javascript
复制
            @Override
            public void afterTextChanged(Editable s) {
                // phone digits without formatting
                phone = s.toString().replaceAll("[^\\d]", "");
                        if (phone.length() == 1) {
                            edtPhoneNumber.setText(s.toString().concat(" "));
                            // move cursor to original position relative to the end of the string
                            edtPhoneNumber.setSelection(edtPhoneNumber.getText().length() - cursorPos);
                        } else {
                            if (pairings.length() >= 2) {
                                pairings = "";
                            }
                            pairings = pairings.concat(phone.substring((phone.length()-1)));
                            if (pairings.length() >= 2) {
                                if (phone.length() < 9) {
                                    edtPhoneNumber.setText(s.toString().concat(" "));
                                } else {
                                    edtPhoneNumber.setText(s.toString());
                                }
                            } else {
                                edtPhoneNumber.setText(s.toString());
                            }
                            // move cursor to original position relative to the end of the string
                            edtPhoneNumber.setSelection(edtPhoneNumber.getText().length() - cursorPos);
                        }
              }

我对这个库的实现如下。使用感兴趣的区域代码实例化后,

代码语言:javascript
复制
AsYouTypeFormatter aytf = PhoneNumberUtil.getInstance().getAsYouTypeFormatter("FR") 

然后,我在afterTextChanged(可编辑的)中有以下代码

代码语言:javascript
复制
                    if(phone.length() > 0){
                        for(int i = 0; i < phone.length(); i++){
                            formattedPhoneNumber = aytf.inputDigit(phone.charAt(i));

                        }
                        //The formatted output shows properly in this EditText but not when I try to put it back into the original one (phoneNumberText)
                        edtPhoneNumber.setText(formattedPhoneNumber);
                        edtPhoneNumber.setSelection(edtPhoneNumber.getText().length() - cursorPos);
                        aytf.clear();
                    }

                    formattedPhoneNumber = null;
                    isPhoneFormatting = false;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-15 16:46:52

我可能错了,但根据wiki,法语数字的数字格式以"0“开头。因此,您的测试输入对LibPhoneNumber无效。France

该计划使用10位数字的封闭编号方案,其中前两位数表示区域:

01法兰西岛

02法国西北部

03法国东北部

04法国东南部

05法国西南部

06及07流动电话服务

08 Freephone (numéro vert)和分担费用服务。

09非地理号码(由Voice服务使用,以前为087号)

如果在测试值前面添加"0“,它的格式似乎是正确的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49807912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档