Java method to verify phone Numbers

  • 2020-04-01 02:59:57
  • OfStack

The project needs to use to verify whether the user's mobile phone number input is legal, on the Internet to find several code, after the test is not through! Finally, I found a piece of code that can be verified. The code seems to be found on a website with a lot of advertisements, I don't know the author! Thanks for sharing! The following is the verification source code:


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;  
}  


Related articles: