国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

Java使用正則表達(dá)式驗證手機(jī)號和電話號碼的方法

2024-07-14 08:43:06
字體:
供稿:網(wǎng)友

一個朋友需要,所以寫了這兩個,話不多說,看代碼

中國電信號段 133、149、153、173、177、180、181、189、199
中國聯(lián)通號段 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號段以前為上網(wǎng)卡專屬號段,如中國聯(lián)通的是145,中國移動的是147等等。
虛擬運(yùn)營商
電信:1700、1701、1702
移動:1703、1705、1706
聯(lián)通:1704、1707、1708、1709、171
衛(wèi)星通信:1349

 /**  * 獲取當(dāng)前的httpSession  * @return  */ public static HttpSession getSession() {  return getRequest().getSession(); } /**  * 手機(jī)號驗證  * @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}$"); // 驗證手機(jī)號   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}$"); // 驗證帶區(qū)號的   p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$");     // 驗證沒有區(qū)號的   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("不符合");  } }

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對VeVb武林網(wǎng)的支持。


注:相關(guān)教程知識閱讀請移步到JAVA教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 靖西县| 太谷县| 武隆县| 手游| 绵阳市| 大英县| 甘泉县| 遂宁市| 广河县| 靖宇县| 阳西县| 墨江| 阜康市| 广东省| 上蔡县| 永德县| 浦县| 桐城市| 南投市| 南宁市| 浦江县| 汽车| 湘乡市| 哈巴河县| 海南省| 台州市| 景洪市| 瑞金市| 安顺市| 陈巴尔虎旗| 玛沁县| 和林格尔县| 海阳市| 临邑县| 青州市| 迭部县| 兰州市| 宁都县| 张家港市| 玉门市| 德清县|