Java正则表达式判断手机号
来源:互联网 发布:淘宝客里的返利管理 编辑:程序博客网 时间:2024/05/01 12:13
故先要整清楚现在已经开放了多少个号码段,国家号码段分配如下:
移动: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卫通)
那么现在就可以正则匹配测试了,
源码
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ClassPathResource {
public static boolean isMobileNO(String mobiles){
Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches()+"---");
return m.matches();
}
public static void main(String[] args) throws IOException {
System.out.println(ClassPathResource.isMobileNO("12016155153"));
}
}
第二种方法:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
String value="手机号";
String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";
Pattern p = Pattern.compile(regExp);
Matcher m = p.matcher(value);
return m.find();//boolean
前面有+86验证方法:
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ClassPathResource {
public static boolean isMobileNO(String mobiles) {
Pattern p = Pattern.compile("^((\\+?86)|((\\+86))?(13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
System.out.println(m.matches() + "---");
return m.matches();
}
public static void main(String[] args) throws IOException {
System.out.println(ClassPathResource.isMobileNO("+8613816155153"));
}
}
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- Java正则表达式判断手机号
- java正则表达式判断手机号
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- java-正则表达式判断手机号
- Java正则表达式判断手机号是否合法
- Java正则表达式判断手机号的例子
- 正则表达式判断手机号
- 正则表达式判断手机号
- java 手机号正则表达式
- 正则表达式判断电信手机号
- 判断手机号的正则表达式
- 正则表达式判断手机号是否合法
- iPhone开发沙盒(SandBox)结构
- Linux调试工具汇总
- Sicily 1750 运动会
- 混世魔王:针对百度搜索引擎的黑白双层优化方案
- UIWebView识别链接代码
- Java正则表达式判断手机号
- Merge Intervals 合并区间@LeetCode
- 使用Settings Bundle为程序添加设置项
- Sicily 1346 金明的预算方案
- 多线程程序中操作的原子性
- iPhone开发部分总结_3_
- 用递归移动盘子
- 随便谈谈——层层递进式的中国式互联网关怀
- acm--查找一个自定数组中位置所对应的值