I. Current number segment (Updated 2017-06-01)
Second, the code
Package Com.linbilin.test;import Java.util.regex.pattern;public class Checkphone {/** landline phone format verification **/private static final String Phone_call_pattern = "^ (?: \ \ (\\d{3,4}\\) |\\d{3,4}-)? \\d{7,8} (?:-\ \d{1,4})? $ ";/** * China Telecom number format verification Phone segment: 133,153,180,181,189,177,1700,173 * **/private static final String china_telecom_ PATTERN = "(?: ^ (?: \ \+86)? 1 (?: 33|53|7[37]|8[019]) \\d{8}$) | (?:^(?:\ \+86) 1700\\d{7}$) ";/** * China Unicom number format verification Phone segment: 130,131,132,155,156,185,186,145,176,1707,1708,1709,175 * **/private static Final String China_unicom_pattern = "(?: ^ (?: \ \+86)? 1 (?: 3[0-2]|4[5]|5[56]|7[56]|8[56]) \\d{8}$) | (?:^(?:\ \+86) 170[7-9]\\d{7}$) ";/** * Simple mobile number check, check the length of the phone number and 1 start */private static final String Simple_phone_check =" ^ (?: \ \+86)? 1\\d{10}$ ";/** * Mobile number format verification * Mobile Phone segment: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184 *, 187,188,147,178,1705 * **/private static final String China_mobile_pattern = "(?: ^ (?: \ \+86)? 1 (?: 3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478]) \\d{8}$) | (?:^(?:\ \+86) 1705\\d{7}$) ";/** * mobile phone number format Check */private statIC final String phone_pattern = new StringBuilder. Append (China_mobile_pattern). Append ("|"). Append (China_telecom_pattern). Append ("|"). Append (China_unicom_pattern). toString ()/** * Cell phone and landline number format check */private static final String Phone_tel_pattern = new StringBuilder. Append (Phone_pattern). Append ("|"). Append ("("). Append (Phone_call_pattern). Append (")"). ToString ();/** * matches multiple numbers in,, or spaces separated formats, such as 17750581369 * 13306061248, ( 596) 3370653,17750581369,13306061248 (0596) 3370653 * @param input * @param separator can specify the delimiter itself, such as ",," means can be separated by comma, commas and spaces * @re Turn */public Static Boolean Checkmultiphone (string input, string separator) {separator = Escapemetacharacterofstr ( separator); String regex = "^ (?!. +["+ separator+"]$) (?:(?:(?:(?: \ \ (\\d{3,4}\\) |\\d{3,4}-)? \\d{7,8} (?:-\ \d{1,4})?) | (?: 1\\d{10})) (?: ["+ separator +"]|$)) +$ "; return match (regex, input);} /** * Escapes the []-^\] character in the string * * @param input * @param separator * @return */private static string Escapemetacharacterofstr (Stri ng input) {String regex = "[-^\\[\\]\\\\]"; return Input.replaceall (Regex," \\\\$0 ");} /** * Only mobile phone number check * * @param input * @return */public static Boolean isphone (String input) {return match (Phone_pattern, input );} /** * Phone number or landline number check * * @param input * @return */public static Boolean Isphoneortel (String input) {System.out.println (phone_t El_pattern); return match (Phone_tel_pattern, input);} /** * Verify Phone number format * * @author Linbilin * @param str * Verify phone String * @return return True otherwise false */public static Boolean Isphonecallnum (String str) {return match (Phone_call_pattern, str);} /** * Verify the format of "telco" mobile phone number * * @author Linbilin * @param str * Check phone String * @return return True otherwise false */public static bool EAN Ischinatelecomphonenum (String str) {return match (China_telecom_pattern, str);} /** * Verify the format of "Unicom" mobile phone number * * @author Linbilin * @param str * Check phone String * @return return True otherwise false */public static bool EAN Ischinaunicomphonenum (String str) {return match (China_unicom_pattern, str);} /** * Verify the format of mobile phone number * * @author Linbilin * @param str * Verify the phone String * @return returns True, otherwise false */public static Boolean ischinamobilephonenum (String str) {return match (China_mobi Le_pattern, str);} /** * Simple mobile number check, check the length of the phone number and 1 start * * @param str * @return */public static Boolean isphonesimple (String str) {return match (SIM Ple_phone_check, str);} /** * Match Function * * @param regex * @param input * @return */private static Boolean match (string regex, string input) {return P Attern.matches (regex, input);}}
Java verification of mobile phone numbers, phone numbers (including the latest telecom, Unicom and mobile numbers)