您的位置:首页 > 其它

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

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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Util
相关文章推荐