kisn888的gravatar头像
kisn888 2016-05-24 15:15:21

java正则表达式判断手机号码,支持多个手机号验证

今天有个需求,是对手机号的校验,想到当初我的183开头的手机号百度都校验不过,特意搜索了下最新的手机号段

http://www.cnblogs.com/zengxiangzhan/p/phone.html 

java正则表达式判断手机号码,支持多个手机号验证

我的需求还有点特殊,需要验证的不是单个手机号,可能是多个手机号,所以用到了递归,

先上测试结果:

java正则表达式判断手机号码,支持多个手机号验证

源代码如下:

public static void main(String[] args) throws Exception {
    	String mobile1="12345677890";
    	String mobile2="17101530373,18301333333";
    	boolean b=isMobile(mobile1);
    	boolean b2=isMobile(mobile2);
    	System.out.println(b+"--"+b2);
}
public static boolean isMobile(String mobile) {
    	boolean flag=false;
    	if(mobile.length()==0){
    		return false;
    	}
    	String[] mobiles=mobile.split(",");
    	int len=mobiles.length;
    	if(len==1){
    		return Pattern.matches("^((13[0-9])|(14[5,7,9])|(15[^4,\\D])|(17[0,1,3,5-8])|(18[0-9]))\\d{8}$", mobile);
    	}else{
    		for(int i=0;i<len;i++){
    			if(isMobile(mobiles[i])){
    				flag=true;
    			}else{
    				flag=false;
    			}
    		}
    	}
    	return flag;    	
    }

打赏

文件名:test.java,文件大小:0.835K 下载
最代码最近下载分享源代码列表最近下载
tyyeng  LV18 2018年7月12日
ly伴夏  LV10 2018年6月3日
aihui523  LV34 2017年8月21日
开码压大  LV4 2017年7月12日
tanshiming  LV18 2016年12月25日
a895786125  LV1 2016年8月30日
liyichu  LV1 2016年8月15日
zyl  LV34 2016年7月16日
soft5200  LV30 2016年6月2日
kong.yee  LV40 2016年5月31日
最代码最近浏览分享源代码列表最近浏览
FZJFZJ  LV3 1月8日
835512308  LV14 2022年7月22日
wjh12345654321  LV14 2021年12月16日
614177611  LV3 2021年9月29日
charleswang  LV7 2021年8月31日
vitowang  LV4 2021年8月11日
别碰我被窝  LV9 2021年5月10日
tyy141013  LV1 2021年4月19日
xwkuku 2021年4月6日
暂无贡献等级
2196316269  LV10 2021年2月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友