混乱的js验证

var img = "", controltype;

new selectArea("spanSelectArea", "btnSelectArea", "divAreaContent", "ulProvince", "ulCity", "cityArea", "ulSelectResult", 5, "divHidden", "closespan2", true);
new dragLayerObj("dragDivHeader");
new provinceControl("spanloc_reg", "btnloc_reg", true);
new provinceControl("spanloc_now", "btnloc_now", true);

function insertError(jqobj, errorBool, mes) { //true就是插入错误标签
    var obj = jqobj;
    var iderror = obj.attr("id") + "messageerror";
    var idok = obj.attr("id") + "ok";
    var mesiderror = document.getElementById(iderror);
    var mesidok = document.getElementById(idok);

    if (errorBool) {
        if (!mesiderror) {
            if (mesidok) {
                mesidok.parentNode.removeChild(mesidok);
            }
            $(obj.parent()).append("<span id='" + iderror + "' style='color:red;margin-left:15px;'>" + mes + "</span>");
        }
        else {
            $(mesiderror).html(mes);
        }
        return false;
    }
    else {
        if (!mesidok) {
            if (mesiderror) {
                mesiderror.parentNode.removeChild(mesiderror);
            }
            $(obj.parent()).append("<span id='" + idok + "' style='color:blue;margin-left:15px;'>" + mes + "</span>");
        }
        else {
            $(mesidok).html(mes);
        }
        return true;
    }
}

$(function() {
    new AjaxUpload('#personimg', { action: '/Ashx/AjaxUpload.ashx', onComplete: function(file, response) {
        if (response != "big") {
            img = response;
            document.getElementById("personimg").src = "/files/temp/" + response + "";
        }
        else {
            alert("图片最大不能超过1m");
        }
    }
    });
    $("#txtStature").bind("blur", function() { gettxtStature(); });
    $("#ddlMarryState").bind("change", function() {
        if ($(this).val() == "0") {
            insertError($(this), true, "请选择婚姻状况");
        }
        else {
            insertError($(this), false, "通过");
        }
    });
    $("#ddlCertificateType").bind("change", function() {
        if ($(this).val() == "0") {
            insertError($(this), true, "请选择证件类型");
        }
        else {
            insertError($(this), false, "通过");
            $("#txtCertificateNum").blur();
        }
    });
    $("#selectyear1,#selectmonth1").bind("change", function() {
        var obj1 = $("#selectyear1");
        var obj2 = $("#selectmonth1");
        if (obj1.val() == "" || obj2.val() == "") {
            insertError(obj1, true, "请选择出生年,月");
        }
        else {
            insertError(obj1, false, "通过");
        }
    });

    $("#selectyear2,#selectmonth2").bind("change", function() {
        var obj1 = $("#selectyear2");
        var obj2 = $("#selectmonth2");
        if (obj1.val() == "" || obj2.val() == "") {
            insertError(obj1, true, "请选择毕业年,月");
        }
        else {
            insertError(obj1, false, "通过");
        }
    });

    $($("#HR_Position_s1>select")[0]).bind("change", function() { getHR_Positon(); });
    $($("#HR_Position_s2>select")[0]).bind("change", function() { getHR_Positon2(); });
    $("#txtWorkYears").bind("blur", function() { gettxtWorkYears(); });
    $("#txtCertificateNum").bind("blur", function() { getPassorport(); });

    $("#ddlzhuanke2").html($("#ddlzhuanke1").html());
    if (typeof (zhuanke2) != "undefined") {
        $("#ddlzhuanke2").val(zhuanke2);
    }
    $("#ddlClass2").html($("#ddlClass1").html());
    $("#ddl2").html($("#ddl1").html());

    $("#txtSchool").bind("blur", function() {
        var str = $(this).val().Trim();
        if (str.length > 0) {
            insertError($(this), false, "通过");
        }
        else {
            return insertError($(this), true, "毕业学校必填");
        }
    });

    $("#txtZhuangYe").bind("blur", function() {
        var str = $(this).val().Trim();
        if (str.length > 0) {
            insertError($(this), false, "通过");
        }
        else {
            return insertError($(this), true, "所学专业必填");
        }
    });

    $("#txtJOB,#txtJob2").bind("blur", function() {
        var str = $(this).val().Trim();
        if (str.length > 0) {
            insertError($(this), false, "通过");
        }
        else {
            return insertError($(this), true, "职位名称必填");
        }
    });


    $("#txtPhone").bind("blur", function() {
        isMobile();
    });

    $("#txtCompanyPhone1").bind("blur", function() { phone1(); });
    $("#txtCompanyPhone2").bind("blur", function() { phone2(); });
    $("#txtCompanyPhone").bind("blur", function() { phone3(); });
    $("#TextJob").bind("blur", function() { getTextJob(); })
    $("#txtPostCode").bind("blur", function() { isPostalCode(); });
    $("#txtWeight").bind("blur", function() { gettxtWeight(); });

    var date = (new Date()).getFullYear();
    var obj = $("#selectyear1");
    if (obj.attr("need") != "no") {
        obj.append("<option value=''>请选择</option>");
    }
    for (var i = date - 6; i >= date - 70; i--) {
        obj.append("<option value='" + i + "'>" + i + "</option>");
    }
    obj = $("#selectyear2");
    if (obj.attr("need") != "no") {
        obj.append("<option value=''>请选择</option>");
    }
    for (var i = date; i >= date - 50; i--) {
        obj.append("<option value='" + i + "'>" + i + "</option>");
    }

    $("#selectmonth2").html($("#selectmonth1").html());

    if (controltype != "update") {
        $("#submitImage").bind("click", function() { submitData(); });
    }
    else {
        $("#submitImage").bind("click", function() { updateData(); });
    }

    $("#txtwebsite").bind("blur", function() { IsURL(); });

    $("#txtOICQ").bind("blur", function() { isOICQ(); });
});

function submitData() {
    if (checkAll()) {
        $("#submitImage").attr("disabled", true);
        var str = "mingzu=" + escape($("#ddlMingZu").val().Trim()) + "&zhengzhimianmao=" + escape($("#ddlpoliticstitle").val().Trim()) + "&zhicheng=" + escape($("#ddlpositiontitle").val().Trim()) + "&zhengjian=" + escape($("#ddlCertificateType").val().Trim()) + "&zhengjianhao=" + escape($("#txtCertificateNum").val().Trim()) + "&birthyear=" + escape($("#selectyear1").val().Trim()) + "&birthmonth=" + escape($("#selectmonth1").val().Trim()) + "&shengao=" + escape($("#txtStature").val().Trim()) + "&tizhong=" + escape($("#txtWeight").val().Trim()) + "&jiehun=" + escape($("#ddlMarryState").val().Trim()) + "&img=" + escape(img) + "";
        str += "&muqiandifang=" + escape($("#spanloc_now").val().Trim()) + "&hukou=" + escape($("#spanloc_reg").val().Trim()) + "&shouji=" + escape($("#txtPhone").val().Trim()) + "&country=" + escape($("#txtCompanyPhone1").val().Trim()) + "&difang=" + escape($("#txtCompanyPhone2").val().Trim()) + "&haoma=" + escape($("#txtCompanyPhone").val().Trim()) + "&youbian=" + escape($("#txtPostCode").val().Trim()) + "&wangzhan=" + encodeURIComponent($("#txtwebsite").val().Trim()) + "&icq=" + escape($("#txtOICQ").val().Trim()) + "";
        str += "&xueli=" + escape($("#ddlEducation").val().Trim()) + "&biyexuexiao=" + escape($("#txtSchool").val().Trim()) + "&biyenian=" + escape($("#selectyear2").val().Trim()) + "&biyeyue=" + escape($("#selectmonth1").val().Trim()) + "&zhuangye=" + escape($("#txtZhuangYe").val().Trim()) + "&zhuangke1=" + escape($("#ddlzhuanke1").val().Trim()) + "&zhuangke2=" + escape($("#ddlzhuanke2").val().Trim()) + "&gaozhong=" + escape($("#txtGaoZhong").val().Trim()) + "&daxue=" + escape($("#txtDaXue").val().Trim()) + "&shuoshi=" + escape($("#txtShuoShi").val().Trim()) + "&boshi=" + escape($("#txtBoShi").val().Trim()) + "&jiaoyu=" + escape($("#Textteacher").val().Trim()) + "";
        str += "&waiyu1=" + escape($("#ddlClass1").val().Trim()) + "&shuiping1=" + escape($("#ddl1").val().Trim()) + "&waiyu2=" + escape($("#ddlClass2").val().Trim()) + "&shuiping2=" + escape($("#ddl2").val().Trim()) + "&guoyu=" + escape($("#ddlChina").val().Trim()) + "&jisuanji=" + escape($("#ddlComputerLevel").val().Trim()) + "&qitatechang=" + escape($("#txtQiTaTeChang").val().Trim()) + "";
        str += "&gongzuonianxian=" + escape($("#txtWorkYears").val().Trim()) + "&gongzuojingyan=" + escape($("#TextJob").val().Trim()) + "&ziwopingjia=" + escape($("#TextValue").val().Trim()) + "";

        $("#spanSelectArea>li").each(function(i, m) {
            str += "&workplace" + (i + 1) + "=" + escape($(m).text());
        });


        str += "&rencaileixing=" + escape($("#ddlqiuzhi").val().Trim()) + "&qiuzhileixing=" + escape($("#ddlrenji").val().Trim()) + "&yuexin=" + escape($("#ddlYueXin").val().Trim()) + "&position1=" + escape($($("#HR_Position_s1>select")[0]).val().Trim()) + "&position2=" + escape($($("#HR_Position_s1>select")[0]).val().Trim()) + "&ptitle1=" + escape($("#txtJOB").val().Trim()) + "&ptitle2=" + escape($("#txtJob2").val().Trim()) + "&heshishangban=" + escape($("#ddlHSshangban").val().Trim()) + ""

        str += "&station1=" + escape($($("#HR_Position_s1>select>option:selected")[0]).text().Trim().replace(/-/g, '')) + "&stationtitle1=" + escape($($("#HR_Position_s1>select>option:selected")[0]).attr("ptitle").Trim()) + "";
        str += "&station2=" + escape($($("#HR_Position_s2>select>option:selected")[0]).text().Trim().replace(/-/g, '')) + "&stationtitle2=" + escape($($("#HR_Position_s2>select>option:selected")[0]).attr("ptitle").Trim()) + "";
        $.ajax(
                 {
                     type: "POST",
                     url: "/Ashx/PersonMember/MemberPersonDefaultManage.ashx?type=addresume",
                     dataType: "text",
                     data: str,
                     success: function(data) {
                         if (data == "ok") {
                             alert("添加简历成功");
                             window.location = "/Member/PersonMember/";
                         }
                         else if (data == "err") {
                             $("#submitImage").attr("disabled", false);
                             alert("系统繁忙,请稍候再试");
                         }
                         else {
                             $("#submitImage").attr("disabled", false);
                             alert("你可能已经有简历,或者你第一步没注册成功,请联系我们");
                         }
                     }
                 }
               );
    }
}

function updateData() {
    if (checkAll()) {
        $("#submitImage").attr("disabled", true);

        var str = "mingzu=" + escape($("#ddlMingZu").val().Trim()) + "&zhengzhimianmao=" + escape($("#ddlpoliticstitle").val().Trim()) + "&zhicheng=" + escape($("#ddlpositiontitle").val().Trim()) + "&zhengjian=" + escape($("#ddlCertificateType").val().Trim()) + "&zhengjianhao=" + escape($("#txtCertificateNum").val().Trim()) + "&birthyear=" + escape($("#selectyear1").val().Trim()) + "&birthmonth=" + escape($("#selectmonth1").val().Trim()) + "&shengao=" + escape($("#txtStature").val().Trim()) + "&tizhong=" + escape($("#txtWeight").val().Trim()) + "&jiehun=" + escape($("#ddlMarryState").val().Trim()) + "&img=" + escape(img) + "";
        str += "&muqiandifang=" + escape($("#spanloc_now").val().Trim()) + "&hukou=" + escape($("#spanloc_reg").val().Trim()) + "&shouji=" + escape($("#txtPhone").val().Trim()) + "&country=" + escape($("#txtCompanyPhone1").val().Trim()) + "&difang=" + escape($("#txtCompanyPhone2").val().Trim()) + "&haoma=" + escape($("#txtCompanyPhone").val().Trim()) + "&youbian=" + escape($("#txtPostCode").val().Trim()) + "&wangzhan=" + encodeURIComponent($("#txtwebsite").val().Trim()) + "&icq=" + escape($("#txtOICQ").val().Trim()) + "";
        str += "&xueli=" + escape($("#ddlEducation").val().Trim()) + "&biyexuexiao=" + escape($("#txtSchool").val().Trim()) + "&biyenian=" + escape($("#selectyear2").val().Trim()) + "&biyeyue=" + escape($("#selectmonth1").val().Trim()) + "&zhuangye=" + escape($("#txtZhuangYe").val().Trim()) + "&zhuangke1=" + escape($("#ddlzhuanke1").val().Trim()) + "&zhuangke2=" + escape($("#ddlzhuanke2").val().Trim()) + "&gaozhong=" + escape($("#txtGaoZhong").val().Trim()) + "&daxue=" + escape($("#txtDaXue").val().Trim()) + "&shuoshi=" + escape($("#txtShuoShi").val().Trim()) + "&boshi=" + escape($("#txtBoShi").val().Trim()) + "&jiaoyu=" + escape($("#Textteacher").val().Trim()) + "";
        str += "&waiyu1=" + escape($("#ddlClass1").val().Trim()) + "&shuiping1=" + escape($("#ddl1").val().Trim()) + "&waiyu2=" + escape($("#ddlClass2").val().Trim()) + "&shuiping2=" + escape($("#ddl2").val().Trim()) + "&guoyu=" + escape($("#ddlChina").val().Trim()) + "&jisuanji=" + escape($("#ddlComputerLevel").val().Trim()) + "&qitatechang=" + escape($("#txtQiTaTeChang").val().Trim()) + "";
        str += "&gongzuonianxian=" + escape($("#txtWorkYears").val().Trim()) + "&gongzuojingyan=" + escape($("#TextJob").val().Trim()) + "&ziwopingjia=" + escape($("#TextValue").val().Trim()) + "";

        $("#spanSelectArea>li").each(function(i, m) {
            str += "&workplace" + (i + 1) + "=" + escape($(m).text());
        });


        str += "&rencaileixing=" + escape($("#ddlqiuzhi").val().Trim()) + "&qiuzhileixing=" + escape($("#ddlrenji").val().Trim()) + "&yuexin=" + escape($("#ddlYueXin").val().Trim()) + "&position1=" + escape($($("#HR_Position_s1>select")[0]).val().Trim()) + "&position2=" + escape($($("#HR_Position_s1>select")[0]).val().Trim()) + "&ptitle1=" + escape($("#txtJOB").val().Trim()) + "&ptitle2=" + escape($("#txtJob2").val().Trim()) + "&heshishangban=" + escape($("#ddlHSshangban").val().Trim()) + ""

        str += "&station1=" + escape($($("#HR_Position_s1>select>option:selected")[0]).text().Trim().replace(/-/g, '')) + "&stationtitle1=" + escape($($("#HR_Position_s1>select>option:selected")[0]).attr("ptitle").Trim()) + "";
        str += "&station2=" + escape($($("#HR_Position_s2>select>option:selected")[0]).text().Trim().replace(/-/g, '')) + "&stationtitle2=" + escape($($("#HR_Position_s2>select>option:selected")[0]).attr("ptitle").Trim()) + "";
        $.ajax(
                 {
                     type: "POST",
                     url: "/Ashx/PersonMember/MemberPersonDefaultManage.ashx?type=updateresume",
                     dataType: "text",
                     data: str,
                     success: function(data) {
                         if (data == "ok") {
                             alert("更新简历成功");
                             window.close();
                         }
                         else if (data == "err") {
                             $("#submitImage").attr("disabled", false);
                             alert("系统繁忙,请稍候再试");
                         }
                         else {
                             $("#submitImage").attr("disabled", false);
                             alert("你可能已经有简历,或者你第一步没注册成功,请联系我们");
                         }
                     }
                 }
               );
    }
}

function checkAll() {
    var errorArr = new Array();
    var result = true;
    var obj = null;
    var str = "";
    var obj2 = null;

    //证件类型
    obj = $("#ddlCertificateType");
    if (obj.val() == "0") {
        insertError(obj, true, "请选择证件类型");
        errorArr.push(obj[0]);
        result = false;
    }

    //证件号
    if (!getPassorport()) {
        errorArr.push($("#txtCertificateNum")[0]);
        result = false;
    }

    //出生年月
    obj = $("#selectyear1");
    obj2 = $("#selectmonth1");

    if (obj.val() == "" || obj2.val() == "") {
        result = insertError(obj, true, "请选择出生年,月");
        if (obj.val() == "") {
            errorArr.push(obj[0]);
        }
        else {
            errorArr.push(obj2[0]);
        }
    }
    else {
        insertError(obj, false, "通过");
    }

    //判断身高
    if (!gettxtStature()) {
        errorArr.push($("#txtStature")[0]);
        result = false;
    }

    //判断体重
    if (!gettxtWeight()) {
        errorArr.push($("#txtWeight")[0]);
        result = false;
    }

    //判断婚否
    obj = $("#ddlMarryState");
    if (obj.val() == "0") {
        insertError(obj, true, "请选择婚姻状况");
        errorArr.push(obj[0]);
        result = false;
    }

    //现在个人地点
    if ($("#spanloc_now").val().length == 0) {
        insertError($("#spanloc_now"), true, "请选择目前所在地");
        errorArr.push($("#spanloc_now")[0]);
        result = false;
    }

    //户口所在地
    if ($("#spanloc_reg").val().length == 0) {
        insertError($("#spanloc_reg"), true, "请选择户口所在地");
        errorArr.push($("#spanloc_reg")[0]);
        result = false;
    }

    //手机号码
    if (!isMobile()) {
        errorArr.push($("#txtPhone")[0]);
        result = false;
    }

    //国家代号
    if (!phone1()) {
        errorArr.push($("#txtCompanyPhone1")[0]);
        result = false;
    }

    //地方代号
    if (!phone2()) {
        errorArr.push($("#txtCompanyPhone2")[0]);
        result = false;
    }

    //号码代号
    if (!phone3()) {
        errorArr.push($("#txtCompanyPhone")[0]);
        result = false;
    }

    //邮编
    if (!isPostalCode()) {
        errorArr.push($("#txtPostCode")[0]);
        result = false;
    }

    //个人主页
    if (!IsURL()) {
        errorArr.push($("#txtwebsite")[0]);
        result = false;
    }

    //OICQ
    if (!isOICQ()) {
        errorArr.push($("#txtOICQ")[0]);
        result = false;
    }

    //判断毕业学校
    obj = $("#txtSchool");
    str = obj.val().Trim();
    if (str.length > 0) {
        insertError(obj, false, "通过");
    }
    else {
        errorArr.push(obj[0]);
        result = insertError(obj, true, "毕业学校必填");
    }

    //毕业年月
    obj = $("#selectyear2");
    obj2 = $("#selectmonth2");

    if (obj.val() == "" || obj2.val() == "") {
        result = insertError(obj, true, "请选择毕业年,月");
        if (obj.val() == "") {
            errorArr.push(obj[0]);
        }
        else {
            errorArr.push(obj2[0]);
        }
    }
    else {
        insertError(obj, false, "通过");
    }

    //专业
    obj = $("#txtZhuangYe");
    str = obj.val().Trim();
    if (str.length > 0) {
        insertError(obj, false, "通过");
    }
    else {
        errorArr.push(obj[0]);
        result = insertError(obj, true, "所学专业必填");
    }

    //判断工作年限
    if (!gettxtWorkYears()) {
        errorArr.push($("#txtWorkYears")[0]);
        result = false;
    }

    //工作经验
    if (!getTextJob()) {
        errorArr.push($("#TextJob")[0]);
        result = false;
    }

    //工作地点
    if (!getWorkPlace()) {
        errorArr.push($("#spanSelectArea")[0]);
        result = false;
    }

    //判断求职意向1
    if (!getHR_Positon()) {
        errorArr.push($("#HR_Position_s1>select")[0]);
        result = false;
    }
    //判断求职意向2
    if (!getHR_Positon2()) {
        errorArr.push($("#HR_Position_s2>select")[0]);
        result = false;
    }

    //职位1
    obj = $("#txtJOB");
    str = obj.val().Trim();
    if (str.length > 0) {
        insertError(obj, false, "通过");
    }
    else {
        errorArr.push(obj[0]);
        result = insertError(obj, true, "求职意向职位必填");
    }

    //职位2
    obj = $("#txtJob2");
    str = obj.val().Trim();
    if (str.length > 0) {
        insertError(obj, false, "通过");
    }
    else {
        errorArr.push(obj[0]);
        result = insertError(obj, true, "求职意向职位必填");
    }

    if (!result) {
        errorArr[0].focus();
    }
    return result;
}

function gettxtStature() {
    var obj = $("#txtStature");
    var str = obj.val().Trim();
    if (str.length > 0) {
        obj.val(str);
        var reg = /^\d{3}$/;
        if (reg.test(str)) {
            if (parseInt(str) > 100) {
                return insertError(obj, false, "通过");
            }
            else {
                return insertError(obj, true, "身高必须大于100的数字");
            }
        }
        else {
            return insertError(obj, true, "身高必须大于100的数字");
        }
    }
    else {
        return insertError(obj, true, "身高必须填写");
    }
}

function gettxtWeight() {
    var obj = $("#txtWeight");
    var str = obj.val().Trim();
    if (str.length > 0) {
        obj.val(str);
        var reg = /^\d{2,3}$/;
        if (reg.test(str)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "体重必须是大于10的数字");
        }
    }
    else {
        return insertError(obj, true, "体重必须填写");
    }
}

function gettxtWorkYears() {
    var obj = $("#txtWorkYears");
    var str = obj.val().Trim();
    if (str.length > 0) {
        obj.val(str);
        var reg = /^\d{1,2}$/;
        if (reg.test(str)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "工作年限必须是两位数字");
        }
    }
    else {
        return insertError(obj, true, "工作年限必须填写");
    }
}

//判断求职意向
function getHR_Positon() {
    var obj = $($("#HR_Position_s1>select")[0]);
    var str = obj.val();
    if (str == "") {
        return insertError($("#HR_Position_s1"), true, "请选择好求职意向");
    }
    else {
        return insertError($("#HR_Position_s1"), false, "通过");
    }
}

function getHR_Positon2() {
    var obj = $($("#HR_Position_s2>select")[0]);
    var str = obj.val();
    if (str == "") {
        return insertError($("#HR_Position_s2"), true, "请选择好求职意向");
    }
    else {
        return insertError($("#HR_Position_s2"), false, "通过");
    }
}

//15位身份证转换为18位,如果参数字符串中有非数字字符,则返回"#"表示参数不正确
function idCardUpdate(_str) {
    var idCard18;
    var regIDCard15 = /^(\d){15}$/;
    if (regIDCard15.test(_str)) {
        var nTemp = 0;
        var ArrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var ArrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        _str = _str.substr(0, 6) + '1' + '9' + _str.substr(6, _str.length - 6);
        for (var i = 0; i < _str.length; i++) {
            nTemp += parseInt(_str.substr(i, 1)) * ArrInt[i];
        }
        _str += ArrCh[nTemp % 11];
        idCard18 = _str;
    }
    else {
        idCard18 = "#";
    }
    return idCard18;
}


//验证身份证号
var aCity = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" }


//是否是有效中国身份证
function isIDCard(sId) {
    sId = sId.Trim();
    if (sId.length == 15) {
        sId = idCardUpdate(sId);
    }
    var iSum = 0;
    var info = "";
    if (!/^\d{17}(\d|x)$/i.test(sId)) return false;
    sId = sId.replace(/x$/i, "a");
    if (aCity[parseInt(sId.substr(0, 2))] == null) return false;
    sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
    var d = new Date(sBirthday.replace(/-/g, "/"));
    if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return false;
    for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
    if (iSum % 11 != 1) return false;
    return true;
}

function getPassorport() {
    var val = $("#txtCertificateNum").val().Trim();
    if (val.length > 0) {
        var str = $("#ddlCertificateType").val();
        if (str != "0") {
            var reg, msg;
            if (str == "身份证") {
                if (!isIDCard(val)) {
                    return insertError($("#txtCertificateNum"), true, "非法身份证号码");
                }
                else {
                    return insertError($("#txtCertificateNum"), false, "通过");
                }
            }
            else if (str == "护照") {
                reg = /^[A-Za-z0-9]+$/;
                msg = "您输入的护照格式错误";
            }
            else if (str == "军人证" || str == "学生证") {
                reg = /^d{1,}$/;
                msg = "您必须输入数字格式";
            }
            if (!reg.test(str)) {
                return insertError($("#txtCertificateNum"), true, msg);
            }
            else {
                return insertError($("#txtCertificateNum"), false, "通过");
            }
        }
        else {
            return insertError($("#txtCertificateNum"), true, "请先选择证件类型");
        }
    }
    else {
        return insertError($("#txtCertificateNum"), true, "证件号必填");
    }
}

function getWorkPlace() {
    var spanSelectArea = $("#spanSelectArea");
    if (spanSelectArea.children().length == 0) {
        return insertError(spanSelectArea, true, "必须选择该岗位工作地区(最多5个)");
    }
    else {
        return insertError(spanSelectArea, false, "通过(最多5个)");
    }
}

//电话号码1
function phone1() {
    var obj = $("#txtCompanyPhone1");
    obj.val(obj.val().Trim());
    var str = obj.val();
    if (str.length > 0) {
        var reg = /^[+]{0,1}(\d){2,3}$/;
        if (reg.test(str)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "国家代码号码格式错误 如:+86");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//电话号码2
function phone2() {
    var obj = $("#txtCompanyPhone2");
    obj.val(obj.val().Trim());
    var str = obj.val();
    if (str.length > 0) {
        var reg = /^(\d){2,4}$/;
        if (reg.test(str)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "区号码格式错误 2-4位数字");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//电话号码3
function phone3() {
    var obj = $("#txtCompanyPhone");
    obj.val(obj.val().Trim());
    var str = obj.val();
    if (str.length > 0) {
        var reg = /^(\d){7,8}$/;
        if (reg.test(str)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "号码必须是 7-8位数字");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//验证手机号码
function isMobile() {
    var obj = $("#txtPhone");
    var s = obj.val().Trim();
    if (s.length > 0) {
        var reg0 = /^13\d{5,9}$/;
        var reg1 = /^153\d{4,8}$/;
        var reg2 = /^159\d{4,8}$/;
        var reg3 = /^0\d{10,11}$/;
        var my = false;
        if (reg0.test(s)) my = true;
        if (reg1.test(s)) my = true;
        if (reg2.test(s)) my = true;
        if (reg3.test(s)) my = true;
        if (my) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "手机号码不正确");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//校验(国内)邮政编码
function isPostalCode() {
    var obj = $("#txtPostCode");
    var s = obj.val().Trim();
    var pattern = /^[0-9]{6}$/;
    if (s != "") {
        if (!pattern.test(s)) {
            return insertError(obj, true, "邮政编码必须是6位数字");
        }
        else {
            return insertError(obj, false, "通过");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//工作经验
function getTextJob() {
    var obj = $("#TextJob");
    var s = obj.val().Trim();
    if (s.length > 0) {
        return insertError(obj, false, "通过");
    }
    else {
        return insertError(obj, true, "工作经验必填");
    }
}

//验证url
function IsURL() {
    var obj = $("#txtwebsite");
    var str_url = obj.val().Trim();
    if (str_url.length > 0) {
        var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" + "(([0-9]{1,3}\.){3}[0-9]{1,3}" + "|" + "([0-9a-z_!~*'()-]+\.)*" + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." + "[a-z]{2,6})" + "(:[0-9]{1,4})?" + "((/?)|" + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
        var re = new RegExp(strRegex);
        if (re.test(str_url)) {
            return insertError(obj, false, "通过");
        } else {
            return insertError(obj, true, "个人网站格式错误");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

//验证OICQ
function isOICQ() {
    var obj = $("#txtOICQ");
    var s = obj.val().Trim();
    if (s.length > 0) {
        var reg = /^\d{1,20}$/;
        if (reg.test(s)) {
            return insertError(obj, false, "通过");
        }
        else {
            return insertError(obj, true, "OICQ格式错误");
        }
    }
    else {
        return insertError(obj, false, "通过");
    }
}

 

 

 

//注册信息检测

var username_long = '您输入的用户名超过18个字符。';
var username_short = '您输入的用户名小于2个字符。';
var username_pass = "可以使用。";

//对用户名进行检测
function checkusername(o) {
    //var reg = "^\\w+$"; //判断是否是中文
    var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){2,19}$/;

    var perusername = document.getElementById("shortname").value;

    if (perusername == "") {
        alert('请填写您的用户名!');
        return false;
    }
    else {

        if (perusername.length < 2) {
            document.getElementById("peruser").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'>  " + username_short + "</font>";
            return;
        }
        else if (perusername.length > 2 && perusername.length < 18) {
            if (foundSpecialChars(perusername)) {
                document.getElementById("peruser").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 用户名不能包含特殊符号!</font>";
                document.getElementById("shortname").focus();
                return;
            }
            if (!reg.exec(perusername)) {
                document.getElementById("peruser").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 用户名只能以英文字母开头!</font>";
                return;
            }
            if (o == "per") {
                var res = persReg.CheckUserName(perusername);
            }
            if (o == "ent") {
                var res = entReg.CheckUserName(perusername);
            }

            if (res.value == "ok")
                document.getElementById("peruser").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'>" + username_pass + "</font>";
            if (res.value == "false")
                document.getElementById("peruser").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 该用户名已经被注册</font>";
            return;
        }
        else if (perusername.length > 18) {
            document.getElementById("peruser").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'>  " + username_long + "</font>";
            return;
        }
    }
}

//密码检测
function checkpwd() {
    var pwd = document.getElementById("pwd1");

    if (pwd.value == "") {

        alert('密码不能为空且大于3个字符!');
        return false;
    }
    else {
        if (pwd.value.length < 3) {
            document.getElementById("errpwd").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 密码必须大于3个字符!</font>";
            return;
        }
        else
            document.getElementById("errpwd").innerHTML = "<img src='images/note_ok.gif' />";
    }

}

//密码的确认检测
function confirmpwd() {
    var chkpassword = document.getElementById("pwd2").value;
    var pwd = document.getElementById("pwd1").value;
    if (chkpassword != "") {
        if (chkpassword != pwd) {
            document.getElementById("errchkpwd").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 两次密码不一致!</font>";
            return;
        }
        else
            document.getElementById("errchkpwd").innerHTML = "<img src='images/note_ok.gif' />";
    }
    else
        document.getElementById("errchkpwd").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 请再输入一次上面的密码!</font>";
    return;
}

//邮箱的检测
function checkemail() {

    var email = document.getElementById("emailusername").value;
    if (email == "") {
        alert('邮箱不能为空!');
        return;
    }
    else {
        if (email.search(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/gi) < 0) {
            document.getElementById("erremail").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 邮箱格式错误!</font>";
            return;
        }
        else {
            var res = persReg.CheckIsRegEmail(email);

            if (res.value == "ok") {
                document.getElementById("erremail").innerHTML = "<img src='images/note_ok.gif' />";
            }
            else {
                document.getElementById("erremail").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 该邮箱已被占用!</font>";
            }

        }
    }
}


//备用邮箱的检测
function checkemailbak() {
    var emailback = document.getElementById("Email2").value;

    var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;

    if (emailback == "") {
        document.getElementById("erremailbak").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'> 该邮箱可以为空!</font>";
    }
    else {
        if (!reg.test(emailback)) {
            document.getElementById("erremailbak").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 请填写正确的邮箱格式!</font>";
            return;
        }
        else {
            document.getElementById("erremailbak").innerHTML = "<img src='images/note_ok.gif' />";
        }
    }
}

//手机号的验证
function checkmobile() {
    var mobile = document.getElementById("cellpone");
    if (mobile.value == "") {
        document.getElementById("errmobile").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'> 手机号可以为空!</font>";
    }
    else {
        if (mobile.value.search(/^(0{0,1}13\d{9}|0{0,1}15\d{9}|0{0,1}18\d{9})$/gi) < 0) {
            document.getElementById("errmobile").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 请填写正确的手机号!</font>";
            return;
        }
        else {
            document.getElementById("errmobile").innerHTML = "<img src='images/note_ok.gif' />";
        }
    }
}

//MSN验证
function checkmsn() {
    var reg = /(\S)+[@]{1}(\S)+[.]{1}(\w)/;
    var ms = document.getElementById("msn");
    if (ms.value == "") {
        document.getElementById("errmsn").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'> MSN号可以为空!</font>";
    }
    else {
        if (!reg.test(ms.value)) {
            document.getElementById("errmsn").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 请填写正确的MSN号!</font>";
            return;
        }
        else {
            document.getElementById("errmsn").innerHTML = "<img src='images/note_ok.gif' />";
        }
    }
}

//QQ号的验证
function checkqq() {
    var q = document.getElementById("qq");
    var reg = /^[1-9]\d{4,8}$/;

    if (q.value == "") {
        document.getElementById("errqq").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'>QQ号可以为空!</font>";
    }
    else {
        if (!reg.test(q.value)) {
            document.getElementById("errqq").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'>请填写正确的QQ号!</font>";
            return;
        }
        else {
            document.getElementById("errqq").innerHTML = "<img src='images/note_ok.gif' />";
        }
    }
}

//联系地址
function checkaddress() {
    var address = document.getElementById("address").value;

    if (address == "") {
        document.getElementById("erraddress").innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'>联系地址可以为空!</font>";
    }
}

//检测是否有非法字符
function foundSpecialChars(str) {
    var chars = "~!@#$%^&*()+=|\/?<>,:;'\"`[]{}";
    for (var i = 0; i < chars.length; i++) {
        if (str.indexOf(chars.substring(i, i + 1)) != -1) {
            return true;
        }
    }
    return false;
}

//检测别名
function checknichen() {
    var nichen = document.getElementById("nichen").value;
    if (nichen != "") {
        if (foundSpecialChars(nichen)) {
            document.getElementById("errni").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 不能包含特殊符号!</font>";
            return;
        }
        else
            document.getElementById("errni").innerHTML = "<img src='images/note_ok.gif' />";
    }
    else
        document.getElementById("errni").innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 昵称不能为空!</font>";
}

//检测上传图片的格式
function CheckFile(sender, arg) {
    var enableExt = ["jpg", "gif", "bmp"]; // add your enable extension on that
    if (arg.Value == "") {
        arg.IsValid = true;
    }
    else {
        var temp = arg.Value.split(".");
        var extension = temp[temp.length - 1];
        extension = extension.toLowerCase();
        var isValid = false;

        for (i = 0; i < enableExt.length; i++) {
            if (extension == enableExt[i]) {
                isValid = true;
            }
        }
        arg.IsValid = isValid;
    }
}


//验证电话号码是否填写正确
function chkTel(tel, errmsg) {
    var modphone = document.getElementById(tel).value

    var reg = /(^([0-9]{3}-?[0-9]{8})|([0-9]{4}-?[0-9]{7})$)/

    if (modphone == "") {
        alert('联系电话不能为空!');
        return;
    }
    else {
        if (!reg.test(modphone)) {
            document.getElementById(errmsg).innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 电话格式错误!</font>";
            return;
        }
        else {
            document.getElementById(errmsg).innerHTML = "<img src='images/note_ok.gif' />";
        }
    }

}


//验证传真
function chkFax(fax, errmsg) {
    var modfax = document.getElementById(fax).value

    var reg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/

    if (modfax == "") {
        document.getElementById(errmsg).innerHTML = "<img src='images/note_ok.gif' /><font color='#009900'>传真可以为空</font>";
    }
    else {
        if (!reg.test(modfax)) {
            document.getElementById(errmsg).innerHTML = "<img src='images/note_error.gif' /><font color='#FF0000'> 传真格式错误!</font>";
            return;
        }
        else {
            document.getElementById(errmsg).innerHTML = "<img src='images/note_ok.gif' />";
        }
    }

}

//资料修改验证
function modcheck() {
    var modlinkman = document.getElementById("linkman");
    if (modlinkman.value == '') {
        alert('联系人不能为空');
        return false;
    }

    var modbieming = document.getElementById("bieming");
    if (modbieming.value == '') {
        alert('公司名不能为空');
        return false;
    }

    var modaddress = document.getElementById("address");
    if (modaddress.value == '') {
        alert('公司地址不能为空!');
        return false;
    }

    var modbusiness = document.getElementById("business");
    if (modbusiness.value == '') {
        alert('主要业务不能为空!');
        return false;
    }

    var verifycode = document.getElementById("verifycode");
    if (verifycode.value == '') {
        alert('验证码不能为空!');
        return false;
    }


}


 

posted on 2010-06-30 23:31  jianshaohui  阅读(659)  评论(0编辑  收藏  举报

导航