|
|
javascript引用的校验函数! |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
经常看别人的代码,感觉他们写的如此精炼。叹为观止啊。今天,我贴上我在网上找到的一个用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脚本语言自动生成。
|
|
相关文章:相关软件: |
|