首页 > 技术文章 > JAVA常用正则表达式

yxw699 2018-09-01 17:25 原文

1.判断是不是数字,包括小数。

private String regex="^(-?\\d+)(\\.\\d+)?$";

if(s.matches(regex)){

}

2.判断是不是手机号

phone.matches("^1[3|4|5|6|7|8|9]\\d{9}$");

3.判断手机号属于哪个运营商

String isChinaMobile = "^134[0-8]\\d{7}$|^(?:13[5-9]|147|198|15[0-27-9]|178|18[2-478])\\d{8}$";//移动
String isChinaUnion = "^(?:13[0-2]|145|15[56]|176|175|166|18[56])\\d{8}$";//联通
String isChinaTelcom = "^(?:133|153|173|177|199|18[019])\\d{8}$";//电信

推荐阅读