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


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



package com.tmall.epp.web.module.util;

import java.util.regex.Pattern;

/**
 * 移动电话、固话、邮编的校验
 * @since 2015.12.15
 */
public class ImportCsvValidate {
	/** 
     * 验证手机号码(支持国际格式,+86135xxxx...(中国内地),+00852137xxxx...(中国香港)) 
     * @param mobile 移动、联通、电信运营商的号码段 
     *<p>移动的号段:134(0-8)、135、136、137、138、139、147(预计用于TD上网卡) 
     *、150、151、152、157(TD专用)、158、159、187(未启用)、188(TD专用)</p> 
     *<p>联通的号段:130、131、132、155、156(世界风专用)、185(未启用)、186(3g)</p> 
     *<p>电信的号段:133、153、180(未启用)、189</p> 
     * @return 验证成功返回true,验证失败返回false 
     */  
	public static boolean isMobile(String mobile){
		String regex = "(\\+\\d+)?1[3458]\\d{9}$";  
		return Pattern.matches(regex, mobile);
	}
	/**
	 * 区号+座机号码+分机号码
	 * @param fixedPhone
	 * @return
	 */
	public static boolean isFixedPhone(String fixedPhone){
		String reg="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|" +
				"(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";
		return Pattern.matches(reg, fixedPhone);
	}
	/** 
     * 匹配中国邮政编码 
     * @param postcode 邮政编码 
     * @return 验证成功返回true,验证失败返回false 
     */ 
	public static boolean isPostCode(String postCode){
		String reg = "[1-9]\\d{5}";
		return Pattern.matches(reg, postCode);
	}
	
	
	
	public static void main(String[] args) {
		String mobile = "18600000000";
		boolean ret = isMobile(mobile);
		System.out.println(ret);
		
		String postCode = "110200";
		ret = isPostCode(postCode);
		System.out.println(ret);
		
		String isFixedPhone = "0571-8888880-111";
		ret = isFixedPhone(isFixedPhone);
		System.out.println(ret);
		
	}

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值