移動、聯通和電信運營商最新號段判斷

 
        /** 
	 * 判斷號碼是聯通,移動,電信中的哪個,
	 * 在使用本方法前,請先驗證號碼的合法性 規則:
	 *  
	 * 中國移動擁有號碼段爲:139,138,137,136,135,134,147,159,158,157(3G),151,152,150,182(3G),188(3G),187(3G);16個號段
	 * 中國聯通擁有號碼段爲:130,131,132,145,155,156(3G),186(3G),185(3G);8個號段
	 * 中國電信擁有號碼段爲:133,1349,153,189(3G),180(3G);5個號碼段
	 * @param mobile要判斷的號碼
	 * @return 返回相應類型:1代表聯通;2代表移動;3代表電信
	 */
	public String getMobileType(String mobile) {

			if (mobile.startsWith("0") || mobile.startsWith("+860")) {
			mobile = mobile.substring(mobile.indexOf("0") + 1, mobile.length());
		}
		List chinaUnicom = Arrays.asList(new String[] { "130", "131", "132",
				"145","155", "156", "186", "185" });
		List chinaMobile1 = Arrays.asList(new String[] { "135", "136", "137",
				"138", "139", "147","150", "151", "152", "157", "158", "159", "182","187",
				"188" });
		List chinaMobile2 = Arrays.asList(new String[] { "1340", "1341",
				"1342", "1343", "1344", "1345", "1346", "1347", "1348" });

		boolean bolChinaUnicom = (chinaUnicom.contains(mobile.substring(0, 3)));
		boolean bolChinaMobile1 = (chinaMobile1
				.contains(mobile.substring(0, 3)));
		boolean bolChinaMobile2 = (chinaMobile2
				.contains(mobile.substring(0, 4)));
		if (bolChinaUnicom)
			return "1";//聯通 
		if (bolChinaMobile1 || bolChinaMobile2)
			return "2"; //移動 
		return "3"; //其他爲電信 

	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章