posts - 17,  comments - 12,  trackbacks - 0

          1、數字

           

           
          01 function testisNum(object)
          02                        {
          03             
          04                         var s =document.getElementById(object.id).value;
          05                 
          06                             if(s!="")
          07                             {
          08                                  if(isNaN(s))
          09                                 {
          10                                  alert("請輸入數字");
          11                                  object.value="";
          12                                  object.focus();
          13                                 }
          14                             }
          15                         }

          2、電話號碼,傳真

           

           
          01 //校驗普通電話、傳真號碼:可以“+”開頭,除數字外,可含有“-”
          02             function isTel(object)
          03             {
          04             //國家代碼(2到3位)-區號(2到3位)-電話號碼(7到8位)-分機號(3位)"
          05   
          06              var s =document.getElementById(object.id).value; 
          07              var pattern =/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
          08              //var pattern =/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/; 
          09                  if(s!="")
          10                  {
          11                      if(!pattern.exec(s))
          12                      {
          13                       alert('請輸入正確的電話號碼:電話號碼格式為國家代碼(2到3位)-區號(2到3位)-電話號碼(7到8位)-分機號(3位)"');
          14                       object.value="";
          15                       object.focus();
          16                      }
          17                  }
          18             }

          3、郵箱

           

           
          01 function Check(object)
          02           
          03         var s =document.getElementById(object.id).value; 
          04              var pattern =/^[a-zA-Z0-9_\-]{1,}@[a-zA-Z0-9_\-]{1,}\.[a-zA-Z0-9_\-.]{1,}$/;
          05                  if(s!="")
          06                  {
          07                      if(!pattern.exec(s))
          08                      {
          09                       alert('請輸入正確的郵箱地址');
          10                       object.value="";
          11                       object.focus();
          12                      }
          13                  }
          14                   
          15         }

          4、手機號碼

           

           
          01 //校驗手機號碼:必須以數字開頭,除數字外,可含有“-”
          02              function isMobile(object)
          03             {
          04             var s =document.getElementById(object.id).value; 
          05             var reg0 = /^13\d{5,9}$/;
          06             var reg1 = /^153\d{4,8}$/;
          07             var reg2 = /^159\d{4,8}$/;
          08             var reg3 = /^0\d{10,11}$/;
          09             var my = false;
          10             if (reg0.test(s))my=true;
          11             if (reg1.test(s))my=true;
          12             if (reg2.test(s))my=true;
          13             if (reg3.test(s))my=true;
          14                 if(s!="")
          15                 {
          16                     if (!my)
          17                     {
          18                        alert('請輸入正確的手機號碼');
          19                        object.value="";
          20                        object.focus();
          21                     }
          22                 }
          23             }
           
          01 //校驗日期
          02             function isdate(object)
          03             {
          04              var s =document.getElementById(object.id).value; 
          05              var pattern =/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/;
          06                  if(s!="")
          07                  {
          08                      if(!pattern.exec(s))
          09                      {
          10                       alert('請輸入正確的日期');
          11                       object.value="";
          12                       object.focus();
          13                      }
          14                  }         
          15             }

          5、郵編

           

           
          01 //校驗(國內)郵政編碼
          02             function isPostalCode(object)
          03             {
          04              var s =document.getElementById(object.id).value; 
          05              var pattern =/^[0-9]{6}$/;
          06                  if(s!="")
          07                  {
          08                      if(!pattern.exec(s))
          09                      {
          10                       alert('請輸入正確的郵政編碼');
          11                       object.value="";
          12                       object.focus();
          13                      }
          14                  }
          15             }

          6、日期

           

           
          01 //校驗日期
          02             function isdate(object)
          03             {
          04              var s =document.getElementById(object.id).value; 
          05              var pattern =/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/;
          06                  if(s!="")
          07                  {
          08                      if(!pattern.exec(s))
          09                      {
          10                       alert('請輸入正確的日期');
          11                       object.value="";
          12                       object.focus();
          13                      }
          14                  }         
          15             }
          posted on 2010-07-21 16:58 asiawang 閱讀(217) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2010年7月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章檔案

          友情連接

          搜索

          •  

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 景泰县| 旺苍县| 磐安县| 兴隆县| 九龙城区| 瑞安市| 申扎县| 平邑县| 公主岭市| 遂宁市| 扬州市| 琼中| 徐汇区| 孙吴县| 龙州县| 乐业县| 金川县| 洛川县| 哈巴河县| 定陶县| 梧州市| 汝城县| 中方县| 兴山县| 江北区| 孝昌县| 射阳县| 新和县| 凤凰县| 苏尼特左旗| 慈利县| 高尔夫| 石阡县| 黄浦区| 丹棱县| 乐清市| 香格里拉县| 连州市| 邮箱| 乐平市| 抚宁县|