EditText电话号码格式
来源:互联网 发布:迅雷5.8绿色优化版 编辑:程序博客网 时间:2024/05/25 19:56
看了网上一些文章,自己改了改,小白<img alt="奋斗" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif" />
/** * * @author Damon * 电话格式EditText */public class PhoneNumberEditText extends EditText implements TextWatcher {public PhoneNumberEditText(Context context, AttributeSet attributeSet) {super(context, attributeSet);}public PhoneNumberEditText(Context context, AttributeSet attributeSet,int defStyle) {super(context, attributeSet, defStyle);}public PhoneNumberEditText(Context context) {super(context);setInputType(InputType.TYPE_CLASS_PHONE);//setFilters(new InputFilter[] { new InputFilter.LengthFilter(13) });addTextChangedListener(this);}@Overridepublic void afterTextChanged(Editable s) { System.out.print(s);}public String getFormatString(String text) {String result = "";if (text.length() == 8) {if (text.length() > 4) {result = text.substring(0, 4) + " "+ text.substring(4, text.length());}} else if (text.length() == 11) {if (text.length() > 7) {result = text.substring(0, 3) + " " + text.substring(3, 7)+ " " + text.substring(7, text.length());} else if (text.length() > 3) {result = text.substring(0, 3) + " "+ text.substring(3, text.length());}} else {result = text;}return result;}boolean flag=false;public String getPhoneNumber() {CharSequence text = super.getText();return text.toString().replaceAll(" ", "");}public String getOriginalNumber() {return getText().toString();}@Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {}@Overridepublic void onTextChanged(CharSequence s, int start, int count, int after) {String text = getPhoneNumber();if (TextUtils.isEmpty(text)) {return;}if (text.length()>13) {text=(String) text.subSequence(0, 13);}flag=!flag;if (flag) {String result = getFormatString(text);setText(result);setSelection(result.length());}}}
0 0
- EditText电话号码格式
- 中国电话号码格式
- 验证邮箱 电话号码格式
- EditText电话号码格式化输入、删除案例
- 自定义EditText之电话号码分段显示
- iphone4 ios7电话号码格式修改
- javascript 正则 判断电话号码格式
- javascript 验证 国际格式 电话号码
- EditText控制输入格式
- EditText输入格式设置
- EditText输入金额格式
- EditText账号输入格式
- jsp中javascript验证电话号码格式
- 使用正则表达式验证电话号码的格式
- java 判断电话号码,邮箱格式是否正确
- java 判断电话号码,邮箱格式是否正确
- 表单验证中的电话号码格式校验
- 常用格式判断(邮箱、电话号码、身份证件)
- 面试准备(一)----什么是xxx
- Linux下php添加新扩展
- 深入理解:Android 编译系统
- linux中的正则表达式
- C语言指针学习六
- EditText电话号码格式
- 关系模式的规范化
- HDOJ find your present (2) 2095
- Java学习篇之---JNI简单实现(续)
- 嵌入式软件开发培训笔记——Java第三天(方法重载、对象的构造与初始化过程分析、封装等)
- Qt杂项笔记
- Simple Android Java & JavaScript Bridge
- 数据链路层组播报文接收问题
- Android性能优化典范(二)