手机号码格式验证

  1. /** 
  2.  * 验证手机格式 
  3.  */  
  4. public static boolean isMobileNO(String mobiles) {  
  5.     /* 
  6.     移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 
  7.     联通:130、131、132、152、155、156、185、186 
  8.     电信:133、153、180、189、(1349卫通) 
  9.     总结起来就是第一位必定为1,第二位必定为3或5或8,其他位置的可以为0-9 
  10.     */  

  11.     String telRegex = "[1][358]\\d{9}";

  12. //"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。  

  13.     if (TextUtils.isEmpty(mobiles))
  14.  return false;  
  15.     else
  16.  return mobiles.matches(telRegex);  

  17.  }


  18. //方式二:根据Matcher 和Pattern 判断
  19. public static boolean isMobilesNumber(String str){
    Pattern pattern = Pattern.compile("1[358][0-9]{9}");
    Matcher matcher = pattern.matcher(str); 
    if (matcher.matches()) {
    return true;
    }else {
    return false;
    }  
     
    }  

你可能感兴趣的:(手机)