加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:25:35 所属栏目:百科 来源:网络整理
导读:/** * 验证是否为电信手机号 * @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
/**
 * 验证是否为电信手机号
 * @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; 
	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读