欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Java使用正則表達式驗證手機號和電話號碼的方法

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

成都創(chuàng)新互聯(lián)基于成都重慶香港及美國等地區(qū)分布式IDC機房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務器托管報價,主機托管價格性價比高,為金融證券行業(yè)成都二樞服務器租用托管,ai人工智能服務器托管提供bgp線路100M獨享,G口帶寬及機柜租用的專業(yè)成都idc公司。

中國電信號段 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等等。
虛擬運營商
電信:1700、1701、1702
移動:1703、1705、1706
聯(lián)通:1704、1707、1708、1709、171
衛(wèi)星通信:1349

 /**
  * 獲取當前的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}$"); // 驗證帶區(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)容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對創(chuàng)新互聯(lián)的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

本文標題:Java使用正則表達式驗證手機號和電話號碼的方法
當前鏈接:http://chinadenli.net/article44/ipcsee.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google微信公眾號服務器托管網(wǎng)站設計公司外貿(mào)網(wǎng)站建設關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管