一個朋友需要,所以寫了這兩個,話不多說,看代碼
中國電信號段 133、149、153、173、177、180、181、189、199
中國聯通號段 130、131、132、145、155、156、166、175、176、185、186
中國移動號段 134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198
其他號段
14號段以前為上網卡專屬號段,如中國聯通的是145,中國移動的是147等等。
虛擬運營商
電信:1700、1701、1702
移動:1703、1705、1706
聯通:1704、1707、1708、1709、171
衛星通信:1349
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/** * 獲取當前的httpsession * @return */ public static httpsession getsession() { return getrequest().getsession(); } /** * 手機號驗證 * @param str * @return 驗證通過返回true */ public static boolean ismobile( final string str) { pattern p = null ; matcher m = null ; boolean b = false ; p = pattern.compile( "^[1][3,4,5,7,8][0-9]{9}$" ); // 驗證手機號 m = p.matcher(str); b = m.matches(); return b; } /** * 電話號碼驗證 * @param str * @return 驗證通過返回true */ public static boolean isphone( final string str) { pattern p1 = null , p2 = null ; matcher m = null ; boolean b = false ; p1 = pattern.compile( "^[0][1-9]{2,3}-[0-9]{5,10}$" ); // 驗證帶區號的 p2 = pattern.compile( "^[1-9]{1}[0-9]{5,8}$" ); // 驗證沒有區號的 if (str.length() > 9 ) { m = p1.matcher(str); b = m.matches(); } else { m = p2.matcher(str); b = m.matches(); } return b; } public static void main(string[] args) { string phone = "13900442200" ; string phone2 = "021-88889999" ; string phone3 = "88889999" ; string phone4 = "1111111111" ; //測試1 if (isphone(phone) || ismobile(phone)){ system.out.println( "1這是符合的" ); } //測試2 if (isphone(phone2) || ismobile(phone2)){ system.out.println( "2這是符合的" ); } //測試3 if (isphone(phone3) || ismobile(phone3)){ system.out.println( "3這是符合的" ); } //測試4 if (isphone(phone4) || ismobile(phone4)){ system.out.println( "4這是符合的" ); } else { system.out.println( "不符合" ); } } |
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對服務器之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
原文鏈接:https://blog.csdn.net/moneyshi/article/details/53466795