简单的工具类,判断手机号码是否合法,密码、验证码格式

来源:互联网 发布: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
原创粉丝点击