您的位置:首页 > 移动开发 > Android开发

Android:最新最全的验证正确手机号码的工具类(2017)

2015-01-18 11:58 363 查看
最新最全的验证正确手机号码的工具类

文 | 莫若吻     

1.代码如下:

(注:大家可根据自己需要进行适当的修改,不懂或者有问题的地方可留言给我。^_^)

/**
* 正则表达式工具类
*
* @author 诺诺
*
*/
public class RegexUtils {

public static boolean isBasePhone(String mobile){
Pattern p1 = Pattern
.compile("^((13[0-9])|(15[^4,\\D])|(177)|(18[0,5-9]))\\d{8}$");
Matcher m1 = p1.matcher(mobile);
return m1.matches();
}

/**
* 验证是否是有效手机号
* 条件:
* 以+86开头或者是11位有效手机号
* 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
* 联通:130、131、132、152、155、156、185、186
* 电信:133、153、180、189、(1349卫通)、177
*
* @param mobiles
* @return
*/
public static boolean isPhoneNum(String mobiles){
Pattern p2 = Pattern
.compile("^(\\+?86)\\d{11}$");
Matcher m = p2.matcher(mobiles);

if(mobiles.length()==11){
return isBasePhone(mobiles);

}else if(mobiles.length()>11 && m.matches()){
String mobile=mobiles.substring(3);
return isBasePhone(mobile);
}
return false;

}
/**
* 验证是否是以“+86”开头的手机号码
* @return
*/
public static boolean isPhonePre(String phoneNum){
Pattern p2 = Pattern
.compile("^(\\+?86)\\d{11}$");
Matcher m = p2.matcher(phoneNum);

if(m.matches()){
String mobile = phoneNum.substring(3);
return isBasePhone(mobile);
}
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: