android 检查电话号码是否合理(含大陆和香港格式)

  1. public class PhoneFormatCheckUtils {  
  2.   
  3.    /** 
  4.    * 大陆号码或香港号码均可 
  5.    */  
  6.     public static boolean isPhoneLegal(String str)throws PatternSyntaxException {  
  7.        return isChinaPhoneLegal(str) || isHKPhoneLegal(str);  
  8.     }  
  9.   
  10.    /** 
  11.     * 大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数 
  12.     * 此方法中前三位格式有: 
  13.     * 13+任意数 
  14.     * 15+除4的任意数 
  15.     * 18+除1和4的任意数 
  16.     * 17+除9的任意数 
  17.     * 147 
  18.     */  
  19.    public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {  
  20.         String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";  
  21.         Pattern p = Pattern.compile(regExp);  
  22.         Matcher m = p.matcher(str);  
  23.         return m.matches();  
  24.    }  
  25.   
  26.     /** 
  27.     * 香港手机号码8位数,5|6|8|9开头+7位任意数 
  28.    */  
  29.     public static boolean isHKPhoneLegal(String str)throws PatternSyntaxException {  
  30.         String regExp = "^(5|6|8|9)\\d{7}$";  
  31.         Pattern p = Pattern.compile(regExp);  
  32.         Matcher m = p.matcher(str);  
  33.         return m.matches();  
  34.    }  
  35.   
  36. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值