Regex批量驗證函式

來源:互聯網
上載者:User
Regex批量驗證函式

function checkData(){
//判斷資料的正確性
 var idSpans= new Array();
 idSpans[0] = new Array("item_4","^[\\s\\S]{1,16}$","productName","商機名稱應在1-16字以內","<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","商機標題應在1-16字以內","<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","商機分類不可為空","<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","產品系列不可為空","<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","商機產地長度應在2-30字以內","<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","商機產地長度應在2-30字以內","<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","商機數量是數字格式","<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","單價只能由數字和小數點組成!!","<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","詳細說明不能小於16個字","<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","商機圖片不可為空","<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="應該選擇最後的分類!";
 document.getElementById("item_3_3").focus();
 return false;
 }
 return true;
}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.