正则表达式匹配移动、联通、电信号码

/**
 * 验证是否为电信手机号
 * @author liubin
 *
 */
public class CheckPhoneNumber {
	/*
	 * 国家号码段分配如下:

	  移动: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
	 */
	
	//匹配移动手机号码
	//public static String str1 = "^1(3[4-9]|5[01789]|8[78])\\d{8}$";
	//匹配移动手机号码
	//public static String str2 = "^1(3[0-2]|5[256]|8[56])\\d{8}$";
	
	//匹配电信号码
	public static String str = "^(18[09]|1[35]3)\\d{8}$";
	/**
	 * 验证单个号码
	 * @param number
	 * @return
	 */
	public static boolean isPhoneNumber(String number){ 
		Pattern p = Pattern.compile(str);  
		Matcher m = p.matcher(number); 
		return m.matches(); 
	} 
	
	/**
	 * 验证批量号码
	 * @param list
	 * @return
	 */
	public static boolean isPhoneNumberAll(String[] list){ 
		Pattern p = Pattern.compile(str);
		for (String string : list) {
			if(string.length()!=11) return false;
			Matcher m = p.matcher(string); 
			if(!m.matches()){
				return false;
			}
		}
		return true; 
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值