function postrequest(id,url){ var pattern = / \/|(pwd)|(\.html)|(\.com)|(script)|(select)|(from)|(print)|(\.js)|(http\:\/\/)|(https\:\/\/)|(www\.)|(\.\.\.)|(\/)|(\\)|(\$)/gim; var ismobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/; var isphone = /^(?:(?:0\d{2,3})-)?(?:\d{7,8})(-(?:\d{3,}))?$/; var isemail = /^([a-za-z]|[0-9])(\w|\-)+@[a-za-z0-9]+\.([a-za-z]{2,4})$/; var flist = $("#"+id).serializearray(); var f = {}; $.each(flist, function (i, field) { f[field.name] = field.value; }); if($("#"+id+" input[name=guest]").length > 0 && (f.guest == '' || (/^[\u4e00-\u9fa5]{1,}$/).test(f.guest) == false || f.guest.tostring().length > 4)){ layer.msg('姓名必须为4个字以内的汉字'); $('#'+id+' *[name=guest]').focus(); }else if($("#"+id+" input[name=tel]").length > 0 && isphone.test(f.tel) == false && ismobile.test(f.tel) == false){ layer.msg('请输入正确的电话号码,如果是固话,区号和号码之间用 - 隔开'); $('#'+id+' *[name=tel]').focus(); }else if($("#"+id+" input[name=email]").length > 0 && f.email != '' && isemail.test(f.email) == false){ layer.msg('请输入您的正确邮箱'); $('#'+id+' *[name=email]').focus(); }else if($("#"+id+" *[name=content]").length > 0 && (f.content == '' || (/^[\da-za-z]+$/).test(f.content) || f.content.tostring().length < 5 || f.content.tostring().length > 200 || pattern.test(f.content))){ layer.msg('留言内容不能含网址和非法字符、长度要在5-200个汉字之间'); $('#'+id+' *[name=content]').focus(); }else if($("#"+id+" input[name=imgvc]").length > 0 && f.imgvc == ''){ layer.msg('请输入验证码'); $('#'+id+' *[name=imgvc]').focus(); }else{ var option = { url:url, type:'post', datatype:'json', success : function(data) { if(data.status == 0){ layer.open({ title:'提交成功', content:data.message, scrollbar:false, btnalign:'c', skin:'my_btn', area:['340px','180px'], }); $('#'+id)[0].reset(); // 提交成功重置 $('#'+id+' .imgcode').click(); } else if(data.status == 1){ layer.msg(data.message); $('#'+id+' .imgcode').click(); } else if(data.status == 2){ layer.msg(data.message); $('#'+id+' .imgcode').click(); } else if(data.status == 3){ layer.msg(data.message); $('#'+id+' .imgcode').click(); } else { layer.msg(data.msg); } }, fail:function (res){ layer.msg(res.msg); } }; $('#'+id).ajaxsubmit(option); } }