ASP表单验证代码改为JS表单验证
我用这段ASP代码实现了表单验证,不过使用ASP代码验证很不方便,想改为JS验证,但不怎么要怎么写JS的,JS的一般基本验证不能为空的我会写,其他复杂些的我就写不出来,老...
我用这段ASP代码实现了表单验证,不过使用ASP代码验证很不方便,想改为JS验证,但不怎么要怎么写JS的,JS的一般基本验证不能为空的我会写,其他复杂些的我就写不出来,老是无效,麻烦大家帮我写一个JS验证表单代码,实现跟下面这段ASP验证代码一样的效果,谢谢,
If Trim(request("kehuname"))="" Then
Response.write"<script>alert(""客户名称不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("cardid"))="" Then
Response.write"<script>alert("""&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("cardtype"))="身份证" Then
If Len(Trim(request("cardid")))=15 or Len(Trim(request("cardid")))=18 Then
else
Response.write"<script>alert(""身份证号码位数不对,请核对并重新填写! "&Copyright&" "");history.back();</script>"
response.end
End If
End If
If Trim(request("tel"))="" Then
Response.write"<script>alert(""联系电话不能为空,请重新输入!"&Copyright&" "");history.back();</script>"
response.end
End If
If Len(Trim(request("tel")))=8 or Len(Trim(request("tel")))=11 Then
else
Response.write"<script>alert(""联系电话有误,请核对并重新填写! "&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("zhifutype"))="1" Then
If Trim(request("))="" Then
Response.write"<script>alert(""银行帐号不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("rebankid"))="" Then
Response.write"<script>alert(""确认帐号不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("bankid"))<>Trim(request("rebankid")) Then
Response.write"<script>alert(""两次输入的银行帐号不一致,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
End If
If Trim(request("typeid"))="1" Then
If Trim(request("taocanej"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request("typeid"))="2" Then
If Trim(request("taocanyr"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request("typeid"))="3" Then
If Trim(request("taocansw"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request(""))="" Then
Response.write"<script>alert("" "&Copyright&" "");history.back();</script>"
response.end
End If 展开
If Trim(request("kehuname"))="" Then
Response.write"<script>alert(""客户名称不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("cardid"))="" Then
Response.write"<script>alert("""&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("cardtype"))="身份证" Then
If Len(Trim(request("cardid")))=15 or Len(Trim(request("cardid")))=18 Then
else
Response.write"<script>alert(""身份证号码位数不对,请核对并重新填写! "&Copyright&" "");history.back();</script>"
response.end
End If
End If
If Trim(request("tel"))="" Then
Response.write"<script>alert(""联系电话不能为空,请重新输入!"&Copyright&" "");history.back();</script>"
response.end
End If
If Len(Trim(request("tel")))=8 or Len(Trim(request("tel")))=11 Then
else
Response.write"<script>alert(""联系电话有误,请核对并重新填写! "&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("zhifutype"))="1" Then
If Trim(request("))="" Then
Response.write"<script>alert(""银行帐号不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("rebankid"))="" Then
Response.write"<script>alert(""确认帐号不能为空,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
If Trim(request("bankid"))<>Trim(request("rebankid")) Then
Response.write"<script>alert(""两次输入的银行帐号不一致,请重新填写!"&Copyright&" "");history.back();</script>"
response.end
End If
End If
If Trim(request("typeid"))="1" Then
If Trim(request("taocanej"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request("typeid"))="2" Then
If Trim(request("taocanyr"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request("typeid"))="3" Then
If Trim(request("taocansw"))="" then
Response.write"<script>alert(""套餐类型还未选择,请重新选择!"&Copyright&" "");history.back();</script>"
response.End
End if
End If
If Trim(request(""))="" Then
Response.write"<script>alert("" "&Copyright&" "");history.back();</script>"
response.end
End If 展开
2个回答
展开全部
你这个用js也很麻烦,js中要设置你上面需要的形式参数,然后使用时,先从数据库中提取kehuname、type等值作为实参,调用js判断即可
更多追问追答
追问
不需要提取数据库的,那2个判断是要获取单先框typeid和zhifutype这2个的值然后来确定taocan和bankid是否需要验证,能否帮写下代码。
追答
function check_input()
{
if (form1.kehuname.value ==0){
alert ("客户名称不能为空,请重新填写!");
form1.kehuname.focus();
return false;
}
if (form1.cardid.value ==0){
alert ("请输入身份证号!");
form1.cardid.focus();
return false;
}
if (form1.cardtype.value =="身份证"){
if (form1.cardid.value.length!=15||form1.cardid.value.length!=18){
alert ("身份证号码位数不对,请核对并重新填写!");
form1.cardid.focus();
return false;
}
}
if (form1.tel.value ==0){
alert ("联系电话不能为空,请重新输入!");
form1.tel.focus();
return false;
}
else
{ if (form1.tel.value.length!=8||form1.tel.value.length!=11)//有些地方的固话还是7位吧?可以自己增加
{ alert ("联系电话有误,请核对并重新填写!");
form1.tel.focus();
return false; }
}
if (form1.zhifutype.value ==1){
if (form1.bankid.value ==0){
alert ("银行帐号不能为空,请重新填写!");
form1.bankid.focus();
return false; }
if (form1.rebankid.value ==0){
alert ("确认帐号不能为空,请重新填写!");
form1.rebankid.focus();
return false; }
if (form1.bankid.value !=form1.rebankid.value){
alert ("两次输入的银行帐号不一致,请重新填写!");
form1.bankid.focus();
return false; }
}
if (form1.typeid.value ==1){
if (form1.taocanej.value ==0){
alert ("套餐类型还未选择,请重新选择!");
form1.taocanej.focus();
return false; }
}
else
if (form1.typeid.value ==2){
if (form1.taocanyr.value ==0){
alert ("套餐类型还未选择,请重新选择!");
form1.taocanyr.focus();
return false; }
}
else
if (form1.typeid.value ==3){
if (form1.taocansw.value ==0){
alert ("套餐类型还未选择,请重新选择!");
form1.taocansw.focus();
return false; }
}
return true;
}
下面的表单调用js的时候,如下
中间略
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询