java正则表达式校验移动电话、固话、邮编的校验

Java正则表达式校验移动电话、固话、邮编的校验



  1. package com.tmall.epp.web.module.util;  
  2.   
  3. import java.util.regex.Pattern;  
  4.   
  5. /** 
  6.  * 移动电话、固话、邮编的校验 
  7.  * @since 2015.12.15 
  8.  */  
  9. public class ImportCsvValidate {  
  10.     /**  
  11.      * 验证手机号码(支持国际格式,+86135xxxx...(中国内地),+00852137xxxx...(中国香港))  
  12.      * @param mobile 移动、联通、电信运营商的号码段  
  13.      *<p>移动的号段:134(0-8)、135、136、137、138、139、147(预计用于TD上网卡)  
  14.      *、150、151、152、157(TD专用)、158、159、187(未启用)、188(TD专用)</p>  
  15.      *<p>联通的号段:130、131、132、155、156(世界风专用)、185(未启用)、186(3g)</p>  
  16.      *<p>电信的号段:133、153、180(未启用)、189</p>  
  17.      * @return 验证成功返回true,验证失败返回false  
  18.      */    
  19.     public static boolean isMobile(String mobile){  
  20.         String regex = "(\\+\\d+)?1[3458]\\d{9}$";    
  21.         return Pattern.matches(regex, mobile);  
  22.     }  
  23.     /** 
  24.      * 区号+座机号码+分机号码 
  25.      * @param fixedPhone 
  26.      * @return 
  27.      */  
  28.     public static boolean isFixedPhone(String fixedPhone){  
  29.         String reg="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|" +  
  30.                 "(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";  
  31.         return Pattern.matches(reg, fixedPhone);  
  32.     }  
  33.     /**  
  34.      * 匹配中国邮政编码  
  35.      * @param postcode 邮政编码  
  36.      * @return 验证成功返回true,验证失败返回false  
  37.      */   
  38.     public static boolean isPostCode(String postCode){  
  39.         String reg = "[1-9]\\d{5}";  
  40.         return Pattern.matches(reg, postCode);  
  41.     }  
  42.       
  43.       
  44.       
  45.     public static void main(String[] args) {  
  46.         String mobile = "18600000000";  
  47.         boolean ret = isMobile(mobile);  
  48.         System.out.println(ret);  
  49.           
  50.         String postCode = "110200";  
  51.         ret = isPostCode(postCode);  
  52.         System.out.println(ret);  
  53.           
  54.         String isFixedPhone = "0571-8888880-111";  
  55.         ret = isFixedPhone(isFixedPhone);  
  56.         System.out.println(ret);  
  57.           
  58.     }  
  59.   

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值