Home >Java >javaTutorial >How to verify phone number in java

How to verify phone number in java

高洛峰
高洛峰Original
2017-01-07 10:04:091605browse

项目需要用到验证用户手机号码输入是否合法,在网上找了好几处代码,经过测试都是不通过的!最后发现了一段代码可以验证通过。代码好像在一个很多广告的网站上找到的,不知道作者!不过还是谢谢原创作者的分享!下面是验证源码:

public static boolean isMobileNO(String mobiles) {  
    boolean flag = false;  
    try {  
        //13********* ,15********,18*********   
        Pattern p = Pattern  
                .compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");  
        Matcher m = p.matcher(mobiles);  
        flag = m.matches();  
    } catch (Exception e) {  
        flag = false;  
    }  
    return flag;  
}


更多java验证电话号码的方法相关文章请关注PHP中文网!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn