正则表达式批量验证函数
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;
}
posted on 2009-04-17 14:26
sanmao 阅读(152)
评论(0) 编辑 收藏