function validate(options) { var current = $("#" + options.target); if (current.attr("validate") == "false") { current.attr("validate", "validing"); current.parent().find(".validate,.field-validation-error").remove(); switch (options.target) { //单位名 case "txtcompany": if ($.trim(current.val()) == "") { current.after("请输入您的单位名称"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //姓名 case "txtusername": if ($.trim(current.val()) == "") { current.after("请输入您的姓名"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //电话 case "txtuserphone": if ($.trim(current.val()) == "") { current.after("请输入您的电话"); if (options.focus) current.focus(); } else if (!/^\d{11}$/.test($.trim(current.val()))) { if (options.focus) current.focus(); current.after("该手机号码格式不正确"); } else if (!/^1[3458]\d{9}$/.test($.trim(current.val()))) { if (options.focus) current.focus(); current.after("该手机号码不存在"); } else { current.attr("validate", "true").after(""); return; } break; //地址 case "txtaddress": if (current != null) { if ($.trim(current.val()) == "") { if (options.focus) current.focus(); current.after("请输入您的地址"); } else { current.attr("validate", "true").after(""); return; } } break; //电子邮箱 case "txtemail": if ($.trim(current.val()) == "") { current.after("请输入您常用的邮箱"); if (options.focus) current.focus(); } else if (!/^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-za-z]{2,4}$/.test($.trim(current.val()))) { current.after("请输入正确格式的邮箱地址"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //留言主题 case "txtsubject": if ($.trim(current.val()) == "") { current.after("请输入要留言的主题"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //版本号 case "txtversion": if ($.trim(current.val()) == "") { current.after("请输入版本号"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //预设值/基本号 case "txtbasicno": if ($.trim(current.val()) == "") { current.after("请输入预设值/基本号"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //意见 case "txtremark": if ($.trim(current.val()) == "") { current.after("请输入您的意见"); if (options.focus) current.focus(); } else { current.attr("validate", "true").after(""); return; } break; //验证码 case "txtsigncode": if ($.trim(current.val()) == "") { current.after("请输入验证码"); if (options.focus) current.focus(); } else{ current.attr("validate", "true").after(""); return; } break; } current.attr("validate", "false"); } } $(document).ready(function () { $("input[validate]").keydown(function (e) { if (e.keycode == 13) { $("#btnsubmit").click(); } }).focus(function () { validate({ target: this.id }); }).blur(function () { validate({ target: this.id }); }) }); function f_submit(){ $("input[validate]").each(function () { validate({ target: $(this).attr("id") }); }); if ($("input:[validate='false']").length < 1) { return true; }else{ return false; } } function change1(){ var randomnum = math.random(); var getimagecode = document.getelementbyid("codes"); getimagecode.src = "admin/code.aspx?" + randomnum; } function f_clear(){ $("input[type='text']").each(function(){ this.value = ""; }) $("#txtcontent").val(""); }