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
}