日期:2014-05-16  浏览次数:20510 次

请帮忙简化一下三段重复的js(除了表单名,其他都一样的)
是一个表单验证

 <script language=javascript>
function postcheck2(){
if (document.wfform2.wfname.value==""){
    alert('请填写姓名!');
document.wfform2.wfname.focus();
return false;
}
var reg1 = /^[\u4e00-\u9fa5]{2,4}$/;
if (!reg1.test(document.wfform2.wfname.value)){
    alert('请填写正确的姓名!');
document.wfform2.wfname.focus();
return false;
}
if (document.wfform2.wfaddress.value==""){
alert('请填写地址!');
document.wfform2.wfaddress.focus();
return false;
}
if (document.wfform2.wfmob.value==""){
alert('请填写手机号码!');
document.wfform2.wfmob.focus();
return false;
}
var reg2 = /^1[3,4,5,8]\d{9}$/;
if (!reg2.test(document.wfform2.wfmob.value)){
    alert('请填写正确的手机号码');
document.wfform2.wfmob.focus();
return false;
}
document.wfform2.wfsubmit.disabled=true;
document.wfform2.wfsubmit.value="正在提交,请稍候...";
return true;
}
function postcheck3(){
if (document.wfform3.wfname.value==""){
    alert('请填写姓名!');
document.wfform3.wfname.focus();
return false;
}
var reg1 = /^[\u4e00-\u9fa5]{2,4}$/;
if (!reg1.test(document.wfform3.wfname.value)){
    alert('请填写正确的姓名!');
document.wfform3.wfname.focus();
return false;
}
if (document.wfform3.wfaddress.value==""){
alert('请填写地址!');
document.wfform3.wfaddress.focus();
return false;
}
if (document.wfform3.wfmob.value==""){
alert('请填写手机号码!');
document.wfform3.wfmob.focus();
return false;
}
var reg2 = /^1[3,4,5,8]\d{9}$/;
if (!reg2.test(document.wfform3.wfmob.value)){
    alert('请填写正确的手机号码');
document.wfform3.wfmob.focus();
return false;
}
document.wfform3.wfsubmit.disabled=true;
document.wfform3.wfsubmit.value="正在提交,请稍候...";
return true;
}
function postcheck4(){
if (document.wfform4.wfname.value==""){
    alert('请填写姓名!');
document.wfform4.wfname.focus();
return false;
}
var reg1 = /^[\u4e00-\u9fa5]{2,4}$/;
if (!reg1.test(document.wfform4.wfname.value)){
    alert('请填写正确的姓名!');
document.wfform4.wfname.focus();
return false;
}
if (document.wfform4.wfaddress.value==""){
alert('请填写地址!');
document.wfform4.wfaddress.focus();
return false;
}
if (document.wfform4.wfmob.value==""){
alert('请填写手机号码!');
document.wfform4.wfmob.focus();
return false;
}
var reg2 = /^1[3,4,5,8]\d{9}$/;
if (!reg2.test(document.wfform4.wfmob.value)){
    alert('请填写正确的手机号码');
document.wfform4.wfmob.focus();
return false;
}
document.wfform4.wfsubmit.disabled=true;
document.wfform4.wfsubmit.value="正在提交,请稍候...";
return true;
}
</script>