在编辑EditText时,在Andorid中更改电话号码格式,如x-xxxx-xxxx-xxxx

时间:2016-11-05 10:08:07

标签: android phonenumberutils

我正在尝试创建一个程序,我可以在EditText中输入我的数字,并自动开始转换为x-xxxx-xxxx-xxxx格式。请指导我。我正在使用这一步

 private static final String PHONE_MSG = "#-###-###-####";

// call this method when you need to check phone number validation
public static boolean isPhoneNumber(EditText editText, boolean required) {
    return isValid(editText, PHONE_REGEX, PHONE_MSG, required);
}

并从我的EdiText中调用它

  etPhoneNumber = (EditText) findViewById(R.id.et_phone_number);
    etPhoneNumber.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            Validation.isPhoneNumber(etPhoneNumber, false);
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after){}
        public void onTextChanged(CharSequence s, int start, int before, int count){}
    });

0 个答案:

没有答案