博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java国际化号码验证方法,国内手机号正则表达式
阅读量:6948 次
发布时间:2019-06-27

本文共 1291 字,大约阅读时间需要 4 分钟。

Java国际化号码验证方法,国内手机号正则表达式

中国电信号段 133、149、153、173、177、180、181、189、199中国联通号段 130、131、132、145、155、156、166、175、176、185、186中国移动号段 134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198其他号段14号段以前为上网卡专属号段,如中国联通的是145,中国移动的是147等等。虚拟运营商电信:1700、1701、1702移动:1703、1705、1706联通:1704、1707、1708、1709、171卫星通信:1349
public static boolean isPhone(String phone) {    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) {        return false;    } else {        Pattern p = Pattern.compile(regex);        Matcher m = p.matcher(phone);        return m.matches();    }}

国际化号码,先判断区号为国内的+86再用国内的号码正则表达式,国外的再逐个添加规则

public static boolean isPhone(String countrycode,String phone) {        if (isNullOrEmpty(phone)) {            return false;        }        //china phone        if("+86".equals(countrycode)) {            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) {                return false;            } else {                Pattern p = Pattern.compile(regex);                Matcher m = p.matcher(phone);                return m.matches();            }        }        return true;    }

 

转载地址:http://wdenl.baihongyu.com/

你可能感兴趣的文章
Web Service 那点事儿(3)—— SOAP 及其安全控制
查看>>
自定义按钮
查看>>
Android手机摄像头作为PC摄像头开发
查看>>
Docker
查看>>
JPush Android 推送如何区分开发、生产环境
查看>>
Redis入门
查看>>
Spring下管理sessionFactory
查看>>
CentOS系统安装MySQL支持远程连接的方法
查看>>
python爱好者QQ群
查看>>
设计模式概念总结
查看>>
mysql根据查询结果更新
查看>>
第二十三讲:tapestry的Delegate和Blocks组件
查看>>
No subject alternative names present的原因
查看>>
分享给和我一样 第一次用git的同学
查看>>
Linux(二)基本使用篇:进入目录,创建文件,编辑文件等
查看>>
利用ClipDrawable实现ImageView展开收缩
查看>>
ajax请求与传统http请求区分
查看>>
Shutting down 'imagePool' pool immediately [Shutdown Hook] 异常处理
查看>>
线程通信机制(生产者与消费者示例)
查看>>
pjsip android
查看>>