威哥不废话,直接上代码:
1.判断方法:
/**
* 判断是否手机号
* Author:William(徐威)
* Create Time:2018-10-05
* @param phone
* @return
*/
public static boolean isMobilePhone(String phone) {
boolean flag=true;
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
if (phone.length() != 11) {
flag= false;
} else {
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(phone);
flag = m.matches();
}
return flag;
}
2.如何使用:
strPhone = etxt_ProductPhoneLogin_Code.getText().toString().trim();
if (strPhone != null && strPhone.length() > 0) {
if(!StringPlus.isMobilePhone(strPhone)){
MessageBox.init(getActivity()).showInfoMsg("请输入正确格式的手机号。");
return;
}
//登录按钮
if (listener != null) {
listener.onLoginPhone(strPhone);
}
etxt_ProductPhoneLogin_Code.setText("");
dismiss();
3.效果图:


本文提供了一个详细的手机号验证方法,通过正则表达式检查输入是否符合中国手机号的格式标准。包括了11位数字的长度检查及前缀合法性验证,适用于各种应用场景。
6831

被折叠的 条评论
为什么被折叠?



