Android版:验证手机号码的正则表达式

  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}";//"[1]"代表第1位为数字1,"[358]"代表第二位可以为3、5、8中的一个,"\\d{9}"代表后面是可以是0~9的数字,有9位。  
  12.     if (TextUtils.isEmpty(mobiles)) return false;  
  13.     else return mobiles.matches(telRegex);  
  14.    }  


//-------------------=========================--------------------------=============================--------------------
  * 验证号码 手机号 固话均可
* */
public static boolean isPhoneNumberValid(String phoneNumber) {
boolean isValid = false;

String expression = "((^(13|15|18)[0-9]{9}$)|(^0[1,2]{1}\\d{1}-?\\d{8}$)|(^0[3-9] {1}\\d{2}-?\\d{7,8}$)|(^0[1,2]{1}\\d{1}-?\\d{8}-(\\d{1,4})$)|(^0[3-9]{1}\\d{2}-? \\d{7,8}-(\\d{1,4})$))";
CharSequence inputStr = phoneNumber;

Pattern pattern = Pattern.compile(expression);

Matcher matcher = pattern.matcher(inputStr);

if (matcher.matches() ) {
isValid = true;
}

return isValid;

}
//===============================================================================================================
public  class  ClassPathResource {
     public  static  boolean  isMobileNO(String mobiles) {
         Pattern p = Pattern
                 .compile( "^((13[0-9])|(15[^4,//D])|(18[0,5-9]))//d{8}$" );
         Matcher m = p.matcher(mobiles);
         System.out.println(m.matches() +  "---" );
         return  m.matches();
     }
 
     public  static  void  main(String[] args)  throws  IOException {
         System.out.println(ClassPathResource.isMobileNO( "18977778989" ));
     }
}
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值