Java匹配國內手機號碼段

目前(2016-12-7)三大運營商最新號段以下

移動號段:
134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188html

聯通號段:
130 131 132 145 155 156 171 175 176 185 186java

電信號段:
133 149 153 173 177 180 181 189
虛擬運營商:
170apache

參考http://www.cnblogs.com/zengxiangzhan/p/phone.html工具

經過java語言寫一個手機號碼段校驗工具類PhoneNumUtil以下:spa

import java.text.ParseException;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * 手機號碼工具類
 */
public class PhoneNumUtil {
	
	public static void main(String[] args) throws ParseException {
		System.out.println(checkPhone("13801246482"));
		System.out.println(checkPhone("17001246482"));
		System.out.println(checkPhone("1501246482"));
	}

	/**
	 * 中國手機號碼校驗
	 * 
	 * @param phone
	 * @return
	 */
	public static boolean checkPhone(String phone) {
		if (StringUtils.isNotBlank(phone)) {
			Pattern regexp = Pattern.compile("^(13[0-9]|14[579]|15[012356789]|17[135678]|18[0-9])[0-9]{8}$");
			if (regexp.matcher(phone).matches()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 中國移動手機號碼校驗
	 * 
	 * @param phone
	 * @return
	 */
	public static boolean checkChinaMobile(String phone) {
		if (StringUtils.isNotBlank(phone)) {
			Pattern regexp = Pattern.compile("^(13[456789]|14[7]|15[012789]|17[8]|18[23478])[0-9]{8}$");
			if (regexp.matcher(phone).matches()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 中國聯通手機號碼校驗
	 * 
	 * @param phone
	 * @return
	 */
	public static boolean checkChinaUnicom(String phone) {
		if (StringUtils.isNotBlank(phone)) {
			Pattern regexp = Pattern.compile("^(13[012]|14[5]|15[56]|17[156]|18[56])[0-9]{8}$");
			if (regexp.matcher(phone).matches()) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 中國電信手機號碼校驗
	 * 
	 * @param phone
	 * @return
	 */
	public static boolean checkChinaTelecom(String phone) {
		if (StringUtils.isNotBlank(phone)) {
			Pattern regexp = Pattern.compile("^(13[3]|14[9]|15[3]|17[37]|18[019])[0-9]{8}$");
			if (regexp.matcher(phone).matches()) {
				return true;
			}
		}
		return false;
	}

}
相關文章
相關標籤/搜索