無線&移動互聯網技術研發

          換位思考·····
          posts - 19, comments - 53, trackbacks - 0, articles - 283
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          手機號碼驗證---(摘)

          Posted on 2009-06-28 13:33 Gavin.lee 閱讀(568) 評論(0)  編輯  收藏 所屬分類: java SE & EE
          package com.Gavin.tools.util;

          /**
           * **********************************************
           * @description 判斷手機號碼
           * 
          @author Gavin.lee
           * @date Jun 28, 2009    4:57:26 AM
           * 
          @version 1.0
           ***********************************************
           
          */

          public class Mobile {
              
          /**
               * 中國移動擁有號碼段為:139,138,137,136,135,134,159,158,157(3G),151,150,188(3G),187(3G);13個號段
               * 中國聯通擁有號碼段為:130,131,132,156(3G),186(3G),185(3G);6個號段
               * 中國電信擁有號碼段為:133,153,189(3G),180(3G);4個號碼段
               
          */

              
          private static String regMobileStr = "^1(([3][456789])|([5][01789])|([8][78]))[0-9]{8}$";
              
          private static String regMobile3GStr = "^((157)|(18[78]))[0-9]{8}$";
              
          private static String regUnicomStr = "^1(([3][012])|([5][6])|([8][56]))[0-9]{8}$";
              
          private static String regUnicom3GStr = "^((156)|(18[56]))[0-9]{8}$";
              
          private static String regTelecomStr = "^1(([3][3])|([5][3])|([8][09]))[0-9]{8}$";
              
          private static String regTelocom3GStr = "^(18[09])[0-9]{8}$";

              
          private String mobile = "";
              
          private int facilitatorType = 0;
              
          private boolean isLawful = false;
              
          private boolean is3G = false;

              
          public Mobile(String mobile) {
                  
          this.setMobile(mobile);
              }


              
          public void setMobile(String mobile) {
                  
          if (mobile == null{
                      
          return;
                  }

                  
          /** 第一步判斷中國移動 */
                  
          if (mobile.matches(Mobile.regMobileStr)) {
                      
          this.mobile = mobile;
                      
          this.setFacilitatorType(0);
                      
          this.setLawful(true);
                      
          if (mobile.matches(Mobile.regMobile3GStr)) {
                          
          this.setIs3G(true);
                      }

                  }

                  
          /** 第二步判斷中國聯通 */
                  
          else if (mobile.matches(Mobile.regUnicomStr)) {
                      
          this.mobile = mobile;
                      
          this.setFacilitatorType(1);
                      
          this.setLawful(true);
                      
          if (mobile.matches(Mobile.regUnicom3GStr)) {
                          
          this.setIs3G(true);
                      }

                  }

                  
          /** 第三步判斷中國電腦 */
                  
          else if (mobile.matches(Mobile.regTelecomStr)) {
                      
          this.mobile = mobile;
                      
          this.setFacilitatorType(2);
                      
          this.setLawful(true);
                      
          if (mobile.matches(Mobile.regTelocom3GStr)) {
                          
          this.setIs3G(true);
                      }

                  }

              }


              
          public String getMobile() {
                  
          return mobile;
              }


              
          public int getFacilitatorType() {
                  
          return facilitatorType;
              }


              
          public boolean isLawful() {
                  
          return isLawful;
              }


              
          public boolean isIs3G() {
                  
          return is3G;
              }


              
          private void setFacilitatorType(int facilitatorType) {
                  
          this.facilitatorType = facilitatorType;
              }


              
          private void setLawful(boolean isLawful) {
                  
          this.isLawful = isLawful;
              }


              
          private void setIs3G(boolean is3G) {
                  
          this.is3G = is3G;
              }


              
          public String toString() {
                  StringBuffer str 
          = new StringBuffer();
                  str.append(
          "mobile:").append(this.getMobile()).append(",")
                  .append(
          "facilitatorType:").append(this.getFacilitatorType()).append(",")
                  .append(
          "isLawful:").append(this.isLawful()).append(",")
                  .append(
          "is3G:").append(this.isIs3G()).append(";");
                  
          return str.toString();
              }


              
          public static void main(String[] args) {
                  Mobile mobile 
          = new Mobile("13088817413");
                  System.out.println(mobile.toString());
              }

          }

          主站蜘蛛池模板: 临城县| 前郭尔| 江门市| 寿宁县| 嘉善县| 泰兴市| 梨树县| 化州市| 津南区| 水城县| 锡林浩特市| 曲沃县| 琼海市| 遵义县| 同仁县| 正宁县| 哈尔滨市| 白河县| 兰州市| 雅江县| 酒泉市| 临西县| 新宾| 建昌县| 额济纳旗| 昌平区| 沅陵县| 启东市| 霍州市| 天气| 舞阳县| 灵丘县| 勐海县| 曲阜市| 新源县| 东乡县| 望都县| 朔州市| 松阳县| 滨州市| 新竹市|