First we need to figure out how many number sections have been opened now, and the country numbers are allocated as follows:
Mobile: 134, 135, 136, 137, 138, 139, 150, 151, 157 (TD), 158, 159, 187, 188
Unicom: 130, 131, 132, 152, 155, 156, 185, 186
Telecommunications: 133, 153, 180, 189, (1349 health)
The rest is to write a regular expression to match, as follows:
Package com.example.offline;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern; /** * * * @author Fx_sky * */public class Phonetest {/** * @param args/public static void Main (string[) arg
s) {//TODO auto-generated method stub String telnum = "10086";
Boolean flag = Ismobiphonenum (Telnum);
System.out.println ("Telnum" +telnum + "Ismobiphonenum" +flag);
Telnum = "13611503575";
Flag = Ismobiphonenum (Telnum);
System.out.println ("Telnum" +telnum + "Ismobiphonenum" +flag); /** * Universal Judgment * @param telnum * @return/public static Boolean Ismobiphonenum (String telnum) {string regex = "^ ((13[0-9]) | (15[0-9]) | (18[0-9])
\\d{8}$ ";
Pattern p = pattern.compile (regex,pattern.case_insensitive);
Matcher m = P.matcher (Telnum);
return m.matches (); /** * More rigorous judgment * @param mobiles * @return/public static Boolean Ismobilenum (String telnum) {pattern p = P Attern.compile ("^ (13[0-9]) |" ( 15[^4,\\D]) | (18[0,5-9]) \\d{8}$ ");
Matcher m = P.matcher (Telnum);
return m.matches ();
}
}
Here are two methods of judging, the first one is more general, the second method is more strict than the first method, and the number 154th is removed; You can choose according to the project.