posts - 27,  comments - 14,  trackbacks - 0
            1 //================================================= 
            2 // 
            3 //    驗證功能的    javascript 
            4 // 
            5 //   最后修改日期: 2005/02/28 
            6 // 
            7 //================================================= 
            8  
            9 ////////////////////////////////////////////////////// 
           10 // 判斷是否閏年  
           11 // 參數 intYear 代表年份的值  
           12 // return   true: 是閏年    
           13 //         false: 不是閏年  
           14 // 
           15 function LeapYear(intYear)  
           16 
           17     if (intYear % 100 == 0
           18     { 
           19         if (intYear % 400 == 0) { return true; } 
           20     }  
           21     else 
           22     {  
           23       if ((intYear % 4== 0) { return true; }  
           24     }  
           25     return false;  
           26 }  
           27  
           28 ////////////////////////////////////////////////////// 
           29 // 驗證日期 
           30 //  
           31 function checkdate(TextID)  
           32 
           33     var flag = true
           34     var searchStr = /^[0-9]{4}-(0[1-9]|[1-9]|1[0-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1])$/ 
           35      
           36     if!searchStr.test(TextID.value) ) 
           37     { 
           38         if(""==TextID.value) 
           39         {} 
           40         else 
           41         { 
           42             TextID.value = ""
           43             alert("您輸入的日期格式錯誤!"); 
           44         } 
           45     } 
           46     else  
           47     {  
           48         var getdate = TextID.value; 
           49          
           50         // 獲得年  
           51         var year=getdate.substr(0,getdate.indexOf('-')); 
           52         // 下面操作獲得月份 
           53         var transition_month=getdate.substr(0,getdate.lastIndexOf('-')); 
           54         var month=transition_month.substr(transition_month.lastIndexOf('-')+1,transition_month.length); 
           55         // 下面操作獲得日期  
           56         var day=getdate.substr(getdate.lastIndexOf('-')+1,getdate.length); 
           57          
           58         if (month.indexOf('0')==0)  
           59         {  
           60             month=month.substr(1,month.length); 
           61         } 
           62         if (day.indexOf('0')==0)  
           63         {  
           64             day=day.substr(1,day.length); 
           65         } 
           66          
           67         // 判斷2月份  
           68         if( month==2 ) 
           69         { 
           70             if (LeapYear(year))  
           71             { 
           72                 if (day>29 || day<1
           73                     flag=false
           74             } 
           75             else 
           76             { 
           77                 if (day>28 || day<1
           78                     flag=false
           79             } 
           80         } 
           81         // 4,6,9,11月份日期不能超過30  
           82         if( (month==4 || month==6 || month==9 || month==11&& (day>30) ) 
           83         { 
           84             flag=false
           85         } 
           86     } 
           87  
           88     if ( flag==false )  
           89     {  
           90         TextID.value = ""
           91         alert("您輸入的日期不合法!");  
           92     } 
           93 
           94  
           95 ///////////////////////////////////////////////// 
           96 // 驗證時間 
           97 //  
           98 function checktime(TextID)  
           99 {  
          100     var flag = true
          101     var searchStr = /^[0-9]{4}-(0[1-9]|[1-9]|1[1-2])-((0[1-9]|[1-9])|1[0-9]|2[0-9]|3[0-1]) ((0[1-9]|[1-9])|1[0-9]|2[0-4]):((0[1-9]|[1-9])|[1-5][0-9]):((0[1-9]|[1-9])|[1-5][0-9])$/ 
          102     if!searchStr.test(TextID.value) ) 
          103     { 
          104         if(""==TextID.value) 
          105         {} 
          106         else 
          107         { 
          108             TextID.value = ""
          109             alert("您輸入的日期時間格式錯誤!"); 
          110          } 
          111     } 
          112     else  
          113     {  
          114         var getdate = TextID.value; 
          115          
          116         // 獲得年  
          117         var year=getdate.substr(0,getdate.indexOf('-')); 
          118         // 下面操作獲得月份 
          119         var transition_month=getdate.substr(0,getdate.lastIndexOf('-')); 
          120         var month=transition_month.substr(transition_month.lastIndexOf('-')+1,transition_month.length); 
          121         // 下面操作獲得日期  
          122         var day=getdate.substr(getdate.lastIndexOf('-')+1,getdate.length); 
          123          
          124         if (month.indexOf('0')==0)  
          125         {  
          126             month=month.substr(1,month.length); 
          127         } 
          128         if (day.indexOf('0')==0)  
          129         {  
          130             day=day.substr(1,day.length); 
          131         } 
          132          
          133         // 判斷2月份  
          134         if( month==2 ) 
          135         { 
          136             if (LeapYear(year))  
          137             { 
          138                 if (day>29 || day<1
          139                     flag=false
          140             } 
          141             else 
          142             { 
          143                 if (day>28 || day<1
          144                     flag=false
          145             } 
          146         } 
          147         // 4,6,9,11月份日期不能超過30  
          148         if( (month==4 || month==6 || month==9 || month==11&& (day>30) ) 
          149         { 
          150             flag=false
          151         } 
          152     } 
          153  
          154     if ( flag==false )  
          155     {  
          156         TextID.value = ""
          157         alert("您輸入的日期不合法!");  
          158     } 
          159 }  
          160  
          161 ///////////////////////////////////////////////// 
          162 // 數字輸入控制 
          163 // 
          164 function NumCheck(obj) 
          165 
          166     if(obj.value==""
          167     { 
          168     } 
          169     else 
          170     { 
          171         if (!isNumeric(obj.value)) 
          172         { 
          173             alert("請輸入整數!"); 
          174             obj.focus(); 
          175             obj.value = ""
          176             return (false); 
          177         } 
          178         else 
          179         {     
          180         } 
          181     }     
          182 
          183  
          184 ///////////////////////////////////////////////// 
          185 // 判斷是否是數字的函數 
          186 // 
          187 function isNumeric(strNumber) 
          188 {  
          189     //return (strNumber.search(/^(-|\+)?\d+(\.\d+)?$/) != -1);  
          190     return (strNumber.search(/^(\d+)?$/!= -1);  
          191 }  
          192  
          193 ///////////////////////////////////////////////// 
          194 // 驗證Email地址 
          195 // 
          196 function checkEmail(TextID) 
          197 
          198     var searchStr = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/ 
          199     if!searchStr.test(TextID.value) ) 
          200     { 
          201         if(""==TextID.value) 
          202         {} 
          203         else 
          204         { 
          205             TextID.value = ""
          206             alert("Email 地址格式錯誤!"); 
          207         } 
          208     } 
          209 
          210  
          211 ///////////////////////////////////////////////// 
          212 // 驗證電話號碼 
          213 // 
          214 function checkPhone(TextID) 
          215 
          216     var searchStr = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/ 
          217     if!searchStr.test(TextID.value) ) 
          218     { 
          219         if(""==TextID.value) 
          220         {} 
          221         else 
          222         { 
          223             TextID.value = ""
          224             alert("電話號碼格式錯誤!"); 
          225         } 
          226     } 
          227 }  
          228  
          229 //-------------------------------------  The end   ----------------------------------------------- 
          posted on 2007-08-28 09:07 Scott.Pan 閱讀(339) 評論(0)  編輯  收藏 所屬分類: 代碼收藏夾
          <2007年8月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 黄冈市| 淮阳县| 阿坝县| 南充市| 工布江达县| 紫金县| 卓尼县| 泾源县| 措美县| 鹤壁市| 阿鲁科尔沁旗| 恩施市| 马鞍山市| 陆河县| 滁州市| 万全县| 丰顺县| 怀来县| 凌云县| 鄂温| 新蔡县| 榆林市| 侯马市| 日照市| 浪卡子县| 襄汾县| 永吉县| 龙南县| 济源市| 黔西县| 重庆市| 平武县| 巴彦淖尔市| 新泰市| 焦作市| 高安市| 涞源县| 柞水县| 万年县| 平陆县| 顺平县|