简单的工具类,判断手机号码是否合法,密码、验证码格式
来源:互联网 发布:mac finder搜索快捷键 编辑:程序博客网 时间:2024/05/08 14:40
public class CheckTextFormatUtils{//判断手机号码 public static boolean checkPhoneNumberFormat(String text) { if (TextUtils.isEmpty(text)) return false; String regx = "((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)"; Pattern pattern = Pattern.compile(regx); Matcher matcher = pattern.matcher(text); return matcher.matches(); }//判断密码 public static boolean checkPasswordFormat(String text) { if (TextUtils.isEmpty(text)) return false; text = text.trim(); if (6 <= text.length() && text.length() <= 32) { return true; } return false; }//判断验证码 public static boolean checkVerificationCodeFormat(String text) { if (TextUtils.isEmpty(text)) return false; text = text.trim(); return text.length() == 6 ? true : false; }}
使用的时候直接调用方法
String phoneNumber = EditUtil.getContent(_accountNameEditText);String password = EditUtil.getContent(_passwordEditText);if (TextUtils.isEmpty(phoneNumber)) { activity.showToastMessage("请输入手机号码"); return;} else { if (!CheckTextFormatUtils.checkPhoneNumberFormat(phoneNumber)) { activity.showToastMessage("手机号码填写有误"); _accountNameEditText.requestFocus(); return; }}if (TextUtils.isEmpty(password)) { activity.showToastMessage("请输入密码"); return;} else { if (!CheckTextFormatUtils.checkPasswordFormat(password)) { activity.showToastMessage("密码填写有误"); _passwordEditText.requestFocus(); return; }}if (NetworkUtil.isNetworkAvaliable(activity)) { // 判断当前网络是否可用 LoginRegisterManager.getInstance().login(phoneNumber, password);} else { activity.showToastMessage("当前网络不可用,请检查网络设置!"); return;}
0 0
- 简单的工具类,判断手机号码是否合法,密码、验证码格式
- 验证 手机号码、密码格式
- 验证输入的手机号码是否合法
- 利用正则表达式判断手机号码格式是否合法
- 正则表达式判断手机号码格式是否合法
- 验证手机号码是否合法
- java验证手机号码是否合法
- js判断手机号码是否合法
- iOS 利用正则表达式判断手机号码格式是否合法
- 手机号码验证工具类
- 验证手机号码工具类
- js验证邮箱,手机号码是否合法
- 正则表达式 判断手机号码是否合法
- 如何判断拨打的手机号码及存储的号码是否合法?
- 判断手机号码格式的方法
- 验证日期格式是否合法
- C# 正则表达式判断手机号码是否合法!
- iOS判断邮箱,手机号码,车牌号是否合法
- leetcode 374. Guess Number Higher or Lower
- iOS 多线程编程<十三、NSOperation图片下载,SDWebImage底层实现原理>
- android studio 环境配置
- 解决新建Xamarin.Forms项目,编译Android项目时出错的问题
- Android自动清理 无用 多余 未引用 未关联资源工具
- 简单的工具类,判断手机号码是否合法,密码、验证码格式
- JVM内存溢出
- SRM146_DIV2
- Android Studio 分包配置
- Eclipse的简单安装
- java实现FTP多线程断点续传,上传下载!
- Web App和Native App 谁将是未来
- android入门开发之linux文件权限(六)
- JAVA中static的作用