怎样判断手机号码是移动的还是联通的

2024-11-13 18:17:05
推荐回答(3个)
回答1:

天天好心情,好好写blog
* 在使用本方法前,请先验证号码的合法性 规则:前三位为130-133 联通 ;前三位为135-139或前四位为1340-1348 移动; 其它的应该为电信
* @param mobile要判断的号码
* @return 返回相应类型:1代表联通;2代表移动;3代表电信*/public static 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,133}) ;
List chinaMobile1 = Arrays.asList(new String[] {135,136,137,138,139,158,159}) ;
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 3 ; //其他为电信}

回答2:

回答3: