How to determine whether the mobile phone number is mobile or connected?

Source: Internet
Author: User

good mood every day, well write a blog
today I encountered a problem, giving a mobile phone number, how to determine whether it is mobile or Unicom. I checked some information and consulted some friends. I don't know whether it is comprehensive. I 'd like to study it with you. Of course, I mean whether the business logic is correct, not the Program itself. Implemented in Java:

/**
* determine the China Unicom, China Mobile, and China Telecom numbers.
* verify the validity rules of the numbers before using this method: the first three digits are 130-133 Unicom, the first three digits are 135-139, or the first four digits are 1340-1348 mobile; other numbers to be determined by China Telecom
* @ Param mobile
* @ return: 1 indicates China Unicom; 2 indicates China Mobile; 3 represents China Telecom
*/
Public static string getmobiletype (string mobile) {
If (mobile. startswith ("0") | mobile. startswith ("+ 860") {
mobile = Mobile. substring (mobile. indexof ("0") + 1, mobile. length ();
}< br> List chinaunicom = arrays. aslist (New String [] {"130", "131", "132", "133"});
List chinamobile1 = arrays. aslist (New String [] {"135", "136", "137", "138", "139", "158 "});
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"; // China Unicom
If (bolchinamobile1 | bolchinamobile2)
Return "2"; // move
Return "3"; // others are Telecom
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.