首页/技术开发/内容

用 JSP 在客户端生成 JavaScript 代码来完成表单校验

技术开发2023-08-22 阅读()
" + "\n" +
"fucCheckLength(document."+formName+"."+inputName+".value)>"+MaxLength+") {" + "\n" +
"alert(\""+errorMsg+".\");" + "\n" +
"document."+formName+"."+inputName+".focus();" + "\n" +
"return(false);" + "\n" +
"}" + "\n\n";
}

/***************************************************************************\
 *public: check the email
 *检查录入框值是否是正确的EMAIL格式
\***************************************************************************/
public void emailCheck(String inputName, String errorMsg){
this.errorCheckStr +=
"if(chkemail(document."+formName+"."+inputName+".value) == 0) {" + "\n" +
"alert(\""+errorMsg+".\");" + "\n" +
"document."+formName+"."+inputName+".focus();" + "\n" +
"return(false);" + "\n" +
"}" + "\n\n";
}

/***************************************************************************\
 *public: check the telephone number
 *检查录入框值是否是电话号码
\***************************************************************************/
public void telCheck(String inputName, String errorMsg){
this.errorCheckStr +=
"if(fucCheckTEL(document."+formName+"."+inputName+".value) == 0) {" + "\n" +
"alert(\""+errorMsg+".\");" + "\n" +
"document."+formName+"."+inputName+".focus();" + "\n" +
"return(false);" + "\n" +
"}" + "\n\n";
}

/***************************************************************************\
 *public: check if the input value contian the prefered string
 *检查录入框值是否是包含给定字串
\***************************************************************************/
public void stringCheck(String inputName, String errorMsg, String string){
this.errorCheckStr +=
"if(document."+formName+"."+inputName+".value.indexOf(\""+string+"\") != 0) {" + "\n" +
"alert(\""+errorMsg+".\");" + "\n" +
"document."+formName+"."+inputName+".focus();" + "\n" +
"return(false);" + "\n" +
"}" + "\n\n";
}

/***************************************************************************\
 *public: check if the input value contain the denyed string
 *检查录入框值是否是包含给禁止的字串
\***************************************************************************/
public void denyStrCheck(String inputName, String errorMsg, String string){
this.errorCheckStr +=
"if (document."+formName+"."+inputName+".value.length == 0 (北联网教程,专业提供视频软件下载)

第1页  第2页  第3页  第4页  第5页  第6页  第7页  第8页  第9页 

……

相关阅读