正則表達(dá)式批量驗(yàn)證函數(shù)

          function checkData(){
          //判斷數(shù)據(jù)的正確性
           var idSpans= new Array();
           idSpans[0] = new Array("item_4","^[\\s\\S]{1,16}$","productName","商機(jī)名稱應(yīng)在1-16字以內(nèi)","<img src='http://www.zj123.com/office/style/1/img/right.gif' border='0'>",true);
           idSpans[1] = new Array("item_5","^[\\s\\S]{1,16}$","Ptitle","商機(jī)標(biāo)題應(yīng)在1-16字以內(nèi)","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",true);
           idSpans[2] = new Array("item_3_2","^[\\s\\S]+$","idItem_3_2Spans","商機(jī)分類(lèi)不能為空","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",true);
           idSpans[3] = new Array("item_7","^[\\s\\S]+$","idItem_7Spans","產(chǎn)品系列不能為空","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",false);
           idSpans[4] = new Array("item_8_1","^[\\s\\S]{2,30}$","idItem_8_1Spans","商機(jī)產(chǎn)地長(zhǎng)度應(yīng)在2-30字以內(nèi)","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",false);
           idSpans[5] = new Array("item_8_2","^[\\s\\S]{2,30}$","idItem_8_1Spans","商機(jī)產(chǎn)地長(zhǎng)度應(yīng)在2-30字以內(nèi)","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",false);
           idSpans[6] = new Array("item_8_4","^[\\d]+$","idItem_8_4Spans","商機(jī)數(shù)量是數(shù)字格式","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",false);
           idSpans[7] = new Array("item_8_6","^[0-9]+[\\.]?[0-9]*$","idItem_8_6Spans","單價(jià)只能由數(shù)字和小數(shù)點(diǎn)組成!!","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",false);
           //idSpans[8] = new Array("item_9","^[\\s\\S]{16,}$","idItem_9Spans","詳細(xì)說(shuō)明不能小于16個(gè)字","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",true);
           //idSpans[9] = new Array("item_1_1","^[\\s\\S]+$","idItem_1_1Spans","商機(jī)圖片不能為空","<img src='http://waimaoseo.qqnn.net/office/style/1/img/right.gif' border='0'>",true);

           var reg ;
           var textValue;
           for(var i=0;i<idSpans.length;i++)
           {
              reg = new RegExp(idSpans[i][1], "igm");
              textValue = document.getElementById(idSpans[i][0]).value;
              if(textValue.length>0||idSpans[i][5])
              {
                  if(reg.test(textValue))
                  {
                   document.getElementById(idSpans[i][2]).innerHTML="<font color='green'>"+idSpans[i][4]+"</font>";
                  }
                  else
                  {
                  try
                  {
                  document.getElementById(idSpans[i][0]).focus();
                  }
                  catch(e)
                  {
                 
                  }
                  document.getElementById(idSpans[i][2]).innerHTML="<font color='red'>"+idSpans[i][3]+"</font>";
                  return false;
                  }
                  alert(textValue);
              }
           }
           //alert(document.getElementById('item_3_2').options.length);
           if(document.getElementById('item_3_3').options.length>0&&document.getElementById('item_3_3').selectedIndex<0)
           {
           document.getElementById("iditem_3_2Spans").innerHTML="應(yīng)該選擇最后的分類(lèi)!";
           document.getElementById("item_3_3").focus();
           return false;
           }
           return true;
          }

           

          posted on 2009-04-17 14:26 sanmao 閱讀(173) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類(lèi)

          隨筆檔案

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 蒲城县| 东乡族自治县| 祁连县| 屏边| 西充县| 绩溪县| 石首市| 康保县| 太仆寺旗| 利川市| 新密市| 精河县| 会宁县| 徐水县| 溧水县| 福安市| 曲沃县| 河北区| 和政县| 商南县| 玉林市| 丰顺县| 化德县| 台北市| 兴业县| 苍南县| 航空| 东方市| 三河市| 开江县| 会昌县| 旬阳县| 霍邱县| 德保县| 南木林县| 江源县| 夏津县| 尖扎县| 承德县| 新绛县| 巫山县|