PHPChina表单验证

<script language="javascript">
function check() {    
var name = document.form1.name.value,
tel 
= document.form1.phone.value,    
age 
= document.form1.age.value,    
qq 
= document.form1.qq.value,
email 
= document.form1.mail.value;    
    
if(name=="") {    
        alert(
"姓名为必填!");    
        document.form1.name.focus();
        
return false;    
    }
    
if (name.replace(/[^\x00-\xff]/g, "**").length > 8 || name.replace(/[^\x00-\xff]/g, "**").length <4 ){        
        alert(
"请认真填写您的姓名!");    
        document.form1.name.focus();
        
return false;    
    }    
    
if(age=='') {
        alert(
"请填写年龄");
        document.form1.age.focus();    
        
return false;    
    }
    
if(isNaN(age) || age>40 || age<10) {
        alert(
"请认真填写年龄");
        document.form1.age.focus();    
        
return false;    
    }    
    
if(tel==""){    
        alert(
"联系方式为必填!");    
        document.form1.phone.focus();
        
return false;    
    }    
    
if (isNaN(tel) || tel.replace(/[^\x00-\xff]/g, "**").length > 18 || tel.replace(/[^\x00-\xff]/g, "**").length<8 ) {    
        alert(
"请认真填写联系方式!");
        document.form1.phone.focus();
        
return false;
    }
    
if(qq == '') {
        alert(
"请填写QQ号码");
        document.form1.qq.focus();
        
return false;
    }
    
if(isNaN(qq) || qq.replace(/[^\x00-\xff]/g, "**").length > 11 || qq.replace(/[^\x00-\xff]/g, "**").length<5  ) {
        alert(
"请输入合法QQ号码");
        document.form1.qq.focus();
        
return false;
    }
        
return true;
}
function war() {
    alert (
"该功能已关闭开放!");
}
</script>
posted @ 2011-10-20 23:00  御清风  阅读(239)  评论(0编辑  收藏  举报