javascript引用的校验函数!

王朝html/css/js·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

经常看别人的代码,感觉他们写的如此精炼。叹为观止啊。今天,我贴上我在网上找到的一个用javascript写的校验函数。希望大家喜欢。。。

function validateFunction(obj){

if(obj==null){

if(document.forms[0])

obj=document.forms[0];

else

return true;

}

var formElements=obj.elements;

var iCount;

for(iCount=0;iCount<formElements.length;iCount++){

if(((formElements[iCount].type=="text")||(formElements[iCount].type=="textarea"))&&(formElements[iCount].value!=null))

{

/**begin**/

switch(formElements[iCount].datatype)

{

case "int":{

if(!checkInteger(formElements[iCount],formElements[iCount].comment))

return false;

break;

}

case "date":{

if(!checkDate(formElements[iCount],formElements[iCount].comment))

return false;

break;

}

case "email":{

if(!checkEmail(formElements[iCount],formElements[iCount].comment))

return false;

break;

}

case "float":{

if(!checkFloat(formElements[iCount],formElements[iCount].comment))

return false;

break;

}

default:{

if((formElements[iCount].maxlength!=null)&&(!checkString(formElements[iCount],formElements[iCount].comment,formElements[iCount].maxlength)))

return false;

break;

}

}

/**end**/

}

if((formElements[iCount].notEmpity!=null)&&(!checkNotNull(formElements[iCount],formElements[iCount].comment)))

return false;

}

return true;

}

这个函数是个主要校验函数,其它的引用函数在以后陆续给出,在在所有的要校验的类型中,要有comment,和datatype属性,例如:<input type=“text“ comment=“test“ name=“text1“ datatype=“int“>,如果,datatype是char型要有maxlength这个类型,或则,无法校验char类型。这些可以通过asp,jsp脚本语言自动生成。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航