﻿// JScript 文件

    function  validInfo(){
        var username=document.getElementById("txtUser").value;
        var company=document.getElementById("txtCompany").value;
        var tel=document.getElementById("txtTel1").value+"-"+document.getElementById("txtTel2").value;
        var mobile=document.getElementById("txtMobile").value;
        var email=document.getElementById("txtEmail").value;
        var fax=document.getElementById("txtFax").value;
        if(username.length==0||tel.length==0||email.length==0)
        {
            alert("以下为必填项：\n====姓名====\n====电话====\n====邮箱====");
            return false;
        }else if(!spaces(username)){
            return false;
        }else if(isTel(tel)==false){
            alert("请输入正确的电话号码");
            return false;
        }else if(isEmail(email)==false){
            alert("请输入正确的邮箱");
            return false;
        }else if(mobile.length!=0){
            if(isMobile(mobile)==false){
                alert("请输入正确的手机号码");
                return false;
            }
        }else if(company.length!=0){
            if(!spaces(company)){
                return false;
                }
        }
    }
    
    function resetAll()
    {
        document.getElementById("txtUser").value="";
        document.getElementById("txtCompany").value="";
        document.getElementById("txtTel1").value="";
        document.getElementById("txtTel2").value="";
        document.getElementById("txtMobile").value="";
        document.getElementById("txtEmail").value="";
        document.getElementById("txtFax").value="";
        document.getElementById("txtAddr").value="";
        document.getElementById("txtMessage").value="";
        document.getElementById("txtUser").focus();
    }
    
    //去空格
    function spaces(obj){
        var count=0;
       for(var i=0;i<obj.length;i++){
           if(obj.charAt(i)!=" ")
	       count++;
       }
       if(count==0){
           alert("您输入的内容不允许全部为空格！");
           return false;
       }
       else
           return true;
    }
    //验证电话
    function isTel(s) 
    { 
        var patrn=/^(\d{3,4}-)?\d{7,8}$/; 
        if (!patrn.exec(s))
            return false 
        return true 
    }
    //验证手机
    function isMobile(s) 
    {
        var patrn=/^(13|15)\d{9}$/; 
        if (!patrn.exec(s))
            return false 
        return true 
    }
    //验证邮箱
    function isEmail(s) 
    {
        var patrn= /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 
        if (!patrn.exec(s))
            return false 
        return true 
    }
    //验证身份证
    function isCode(s)
    {
         //身份证正则表达式(15位) 
        var patrn1=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/; 
        //身份证正则表达式(18位) 
        var patrn2=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[A-Z])$/; 
        if(patrn1.exec(s)||patrn2.exec(s))
            return true;
        return false;
    }
    //验证邮编
    function isPostCode(s){
        var patrn=/^\d{6}$/;
        if(patrn.exec(s))
            return true;
        else return false;
    }
    //验证总分
    function isFraction(s){
        var patrn=/^\d{3}$/;
        if(patrn.exec(s)){
            if(s<1||s>750){
                return false;
            }
            else
                return true;
        }
        else return false;
    }
