android 判断 手机号码、邮编、Email邮箱、是否正确还有qq号


转自:http://blog.csdn.net/gao_chun/article/details/39580363?utm_source=tuicool&utm_medium=referral

java-正则表达式判断手机号


要更加准确的匹配手机号码只匹配11位数字是不够的,比如说就没有以144开始的号码段,

故先要整清楚现在已经开放了多少个号码段,国家号码段分配如下:

移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

联通:130、131、132、152、155、156、185、186

电信:133、153、180、189、(1349卫通)

那么现在就可以正则匹配测试了,

[java] view plain copy
print?在CODE上查看代码片派生到我的代码片

    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);    
      
        return m.matches();    
      
      }  



第二种方法:

[java] view plain copy print?在CODE上查看代码片派生到我的代码片

    String value="手机号";    
      
    String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";    
      
    Pattern p = Pattern.compile(regExp);    
      
    Matcher m = p.matcher(value);    
      
      return m.find();//boolean  




java-正则表达式判断 邮编

中国邮政编码为6位数字,第一位不为0
[java] view plain copy print?在CODE上查看代码片派生到我的代码片

    String str = "^[1-9][0-9]{5}$";  
     /** 
        * 判断邮编 
        * @param paramString 
        * @return 
        */  
       public static boolean isZipNO(String zipString){  
           String str = "^[1-9][0-9]{5}$";  
           return Pattern.compile(str).matcher(zipString).matches();  
       }  




java-正则表达式判断 Email邮箱 是否合法
[java] view plain copy print?在CODE上查看代码片派生到我的代码片

    /** 
        * 判断邮箱是否合法 
        * @param email 
        * @return 
        */  
       public static boolean isEmail(String email){    
           if (null==email || "".equals(email)) return false;      
           //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配    
           Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配    
           Matcher m = p.matcher(email);    
           return m.matches();    
       }   


QQ号

 public static boolean isQQCorrect(String str)
 {
  String  regex ="[1-9][0-9]{4,14}";
  Pattern p = Pattern.compile(regex); 
  Matcher m = p.matcher(str); 
  return m.matches(); 
  
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值