手机号添加空格形成(3-4-4)格式

一、手机号转换成3-4-4格式

public String getMobileFormat(String theMobileStr){

     return theMobileStr.substring(0,3) + "" + theMobileStr.substring(3,7) + "" + theMobileStr.substring(7);

}

二、手机号输入时自动添加空格形成3-4-4格式

  1. final EditText et_phone = (EditText) findViewById(R.id.et_phone);  
  2.         et_phone.addTextChangedListener(new TextWatcher() {  
  3.             @Override  
  4.             public void onTextChanged(CharSequence s, int start, int before, int count) {  
  5.                 if (count == 1){  
  6.                     int length = s.toString().length();  
  7.                     if (length == 3 || length == 8){  
  8.                         et_phone.setText(s + " ");  
  9.                         et_phone.setSelection(et_phone.getText().toString().length());  
  10.                     }  
  11.                 }  
  12.             }  
  13.             @Override  
  14.             public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,  
  15.                     int arg3) {  
  16.                   
  17.             }  
  18.             @Override  
  19.             public void afterTextChanged(Editable arg0) {  
  20.             }  
  21.         }); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值