夏天到了

          雨季過后,是蘑菇生長的季節

           

          IP地址合法性檢查代碼

          private static String IPComp = "0123456789.";

          public void CheckIP(String IP){
             int i;
             int index;
             String cur;
          //判斷是否存在非IP字符
             for (i = 0;i < IP.length();i++){
              if (IPComp.indexOf(IP.charAt(i)) == -1){
               throw new yourException(yourErrorString);
              }   
             }
          //變換IP為'xxx.'重復的格式
             IP = IP + ".";
          //分別獲得前四個'xxx.'檢查
             for (i = 1;i <= 4;i++){
          //判斷底i個'xxx.'是否存在(i<=4)
              index = IP.indexOf('.');
              if (index == -1){
               throw new yourException(yourErrorString);
              }
              else{
          //獲得數字,檢查數字范圍
               cur = IP.substring(0,index);
               IP = IP.substring(index + 1);
               if (cur.length() > 0 && cur.length() <= 3){
                //change cur to int
                int num = 0;
                for (index = 0;index < cur.length();index++){
                 num = num * 10 + (int)cur.charAt(index) - 48;      
                }
                if (num > 255){
                 throw new yourException(yourErrorString);
                }
               }
               else{
                throw new yourException(yourErrorString);
               }
              }
             }
          //檢查是否有多的'xxx.'
             if (IP.indexOf('.') != -1){
              throw new yourException(yourErrorString);
             }
            }

          posted on 2005-07-27 17:50 蘑菇 閱讀(1265) 評論(0)  編輯  收藏 所屬分類: 代碼實現--JAVA

          導航

          統計

          公告

          其實生活很簡單

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 斗六市| 亳州市| 垦利县| 丽江市| 福州市| 无棣县| 鹤山市| 措勤县| 文水县| 顺平县| 隆尧县| 南郑县| 监利县| 大丰市| 丰宁| 腾冲县| 仙游县| 庆阳市| 开平市| 张北县| 竹溪县| 临夏市| 海城市| 大冶市| 南开区| 广饶县| 龙山县| 台南市| 依安县| 巩义市| 溆浦县| 通城县| 安顺市| 隆子县| 澎湖县| 沙田区| 高台县| 剑川县| 潮州市| 南京市| 孟连|