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

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凉城┓.〆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值