<script type="text/javascript">
<!--
function formcheck(){
CorpName =document.form1.CorpName.value;
tel =document.form1.tel.value;
faxes =document.form1.faxes.value;
linkman =document.form1.linkman.value;
combinedSet =document.form1.combinedSet.value;
email =document.form1.email.value;
exhibit =document.form1.exhibit.checked;
visit =document.form1.visit.checked;
conference =document.form1.conference.checked;
if(document.form1.CorpName.value.length <2)
{
alert("公司名称太短,请重新输入!");
document.form1.CorpName.focus();
return false;
}
if(tel =="" && combinedSet == "")
{
alert("电话和手机不能都为空,至少输入一个!");
document.form1.tel.focus();
return false;
}
if(tel !="")
{
if(/^/d+/g.test(tel) == false || tel.length <10 || tel.length >12 )
{
alert("电话号码不正确!");
document.form1.tel.focus();
return false;
}
}
if(combinedSet !="")
{
if(/^/d+/g.test(combinedSet) == false || combinedSet.length !=11 )
{
alert("手机号码不正确!");
document.form1.combinedSet.focus();
return false;
}
}
if(faxes !="")
{
if(/^/d+/g.test(faxes) == false || faxes.length <10 || faxes.length >12 )
{
alert("传真不正确!");
document.form1.faxes.focus();
return false;
}
}
if(linkman == "")
{
alert("联系人不能为空!");
document.form1.linkman.focus();
return false;
}
if(email == "" || email.match("@") == false || email.match(".") == false )
{
alert("邮箱不能为空或格式不正确!");
document.form1.email.focus();
return false;
}
if(exhibit == false && visit == false && conference == false)
{
alert("我有兴趣中三项必须选一项!");
document.form1.exhibit.checked = true;
document.form1.exhibit.focus();
return false;
}
//document.form1.onsubmit();
//alert(exhibit+visit+conference);
//document.form1.exhibit.
return true;
}
//-->
</script>
<form action="" method="post" enctype="multipart/form-data" name="form1" onSubmit="return formcheck();">
<table width="0" border="0">
<tr>
<td width="778">有兴趣参展、参会、参观的人士,请填写以下内容并提交:</td>
</tr>
<tr>
<td><p>公司名称:
<input type="text" name="CorpName">
电话:
<input type="text" name="tel">
传真:
<input type="text" name="faxes">
</p></td>
</tr>
<tr>
<td>联系人:
<input type="text" name="linkman">
手机:
<input type="text" name="combinedSet">
邮箱:
<input type="text" name="email"></td>
</tr>
<tr>
<td>我有兴趣:
<input type="checkbox" name="exhibit" value="参展请与我联系">
参展请与我联系
<input type="checkbox" name="visit" value="参观请寄参观门票">
参观请寄参观门票
<input type="checkbox" name="conference" value="参加会议请和我联系">
参加会议请和我联系</td>
</tr>
<tr>
<td height="28" align="center">
<input type="submit" name="Submit" value="确认提交"></td>
</tr>
</table>
</form>
Javascript 写的一个简单表单验证
最新推荐文章于 2025-08-22 11:32:18 发布