简单的工具类,判断手机号码是否合法,密码、验证码格式
2016-10-24 14:00
525 查看
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;}
相关文章推荐
- 正则表达式判断手机号码格式是否合法
- 利用正则表达式判断手机号码格式是否合法
- php 表单校验函数库(判断email格式是否正确、http地址是否合法有效、手机号码是否合法)
- 校验出生日期,校验身份证格式,校验会员账户:9开头数字,校验手机号码是否合法,判断字符串中的url是否都是图片格式字符串,通过图片url读取图片并将图片转换成base64编码
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- 判断邮箱,手机号码,身份证,用户名,昵称等输入格式是否正确的 正则表达式
- 如何判断拨打的手机号码及存储的号码是否合法?
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- oracle判断手机号码是否合法
- iOS判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- js正则表达式——验证邮箱格式、邮编、身份证号码、是否为空、下拉框选项、密码、手机号码、电话号码
- NSString+Check, iOS 判断手机号码格式是否正确
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)
- ios判断邮箱,手机号码,车牌号是否合法(正则表达)