/* Validform version 5.3.2 By sean during April 7, 2010 - March 26, 2013 For more information, please visit http://validform.rjboy.cn Validform is available under the terms of the MIT license. */ (function($,win,undef){var errorobj=null,msgobj=null,msghidden=true;var tipmsg={tit:"提示信息",w:{"*":"不能为空!","*6-16":"请填写6到16位任意字符!","n":"请填写数字!","n6-16":"请填写6到16位数字!","s":"不能输入特殊字符!","s6-18":"请填写6到18位字符!","p":"请填写邮政编码!","m":"请填写手机号码!","e":"邮箱地址格式不对!","url":"请填写网址!","idcard":"身份证格式不正确!"},def:"请填写正确信息!",undef:"datatype未定义!",reck:"两次输入的内容不一致!",r:"",c:"正在检测信息…",s:"请{填写|选择}{0|信息}!",v:"所填信息没有经过验证,请稍后…",p:"正在提交数据…"};$.Tipmsg=tipmsg;var Validform=function(forms,settings,inited){var settings=$.extend({},Validform.defaults,settings);settings.datatype&&$.extend(Validform.util.dataType,settings.datatype);var brothers=this;brothers.tipmsg={w:{}};brothers.forms=forms;brothers.objects=[];if(inited===true){return false}forms.each(function(){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";var curform=this;curform.settings=$.extend({},settings);var $this=$(curform);curform.validform_status="normal";$this.data("tipmsg",brothers.tipmsg);$this.delegate("[datatype]","blur",function(){var subpost=arguments[1];Validform.util.check.call(this,$this,subpost)});$this.delegate(":text","keypress",function(event){if(event.keyCode==13&&$this.find(":submit").length==0){$this.submit()}});Validform.util.enhance.call($this,curform.settings.tiptype,curform.settings.usePlugin,curform.settings.tipSweep);curform.settings.btnSubmit&&$this.find(curform.settings.btnSubmit).bind("click",function(){$this.trigger("submit");return false});$this.submit(function(){var subflag=Validform.util.submitForm.call($this,curform.settings);subflag===undef&&(subflag=true);return subflag});$this.find("[type='reset']").add($this.find(curform.settings.btnReset)).bind("click",function(){Validform.util.resetForm.call($this)})});if(settings.tiptype==1||(settings.tiptype==2||settings.tiptype==3)&&settings.ajaxPost){creatMsgbox()}};Validform.defaults={tiptype:1,tipSweep:false,showAllError:false,postonce:false,ajaxPost:false};Validform.util={dataType:{"*":/[\w\W]+/,"*6-16":/^[\w\W]{6,16}$/,"n":/^\d+$/,"n6-16":/^\d{6,16}$/,"s":/^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]+$/,"s6-18":/^[\u4E00-\u9FA5\uf900-\ufa2d\w\.\s]{6,18}$/,"p":/^[0-9]{6}$/,"m":/^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|18[0-9]{9}|17[0-9]{9}$/,"e":/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,"url":/^(\w+:\/\/)?\w+(\.\w+)+.*$/,"idcard":/^\d{15}(\d{2}[A-Za-z0-9])?$/},toString:Object.prototype.toString,isEmpty:function(val){return val===""||val===$.trim(this.attr("tip"))},getValue:function(obj){var inputval,curform=this;if(obj.is(":radio")){inputval=curform.find(":radio[name='"+obj.attr("name")+"']:checked").val();inputval=inputval===undef?"":inputval}else{if(obj.is(":checkbox")){inputval="";curform.find(":checkbox[name='"+obj.attr("name")+"']:checked").each(function(){inputval+=$(this).val()+","});inputval=inputval===undef?"":inputval}else{inputval=obj.val()}}inputval=$.trim(inputval);return Validform.util.isEmpty.call(obj,inputval)?"":inputval},enhance:function(tiptype,usePlugin,tipSweep,addRule){var curform=this;curform.find("[datatype]").each(function(){if(tiptype==2){if($(this).parents(".formControls").next().find(".Validform_checktip").length==0){$(this).parents(".formControls").next().append("");$(this).siblings(".Validform_checktip").remove()}}else{if(tiptype==3||tiptype==4){if($(this).siblings(".Validform_checktip").length==0){$(this).parent().append("");$(this).parent().next().find(".Validform_checktip").remove();$(this).parents(".formControls").next().find(".Validform_checktip").remove()}}}});curform.find("input[recheck]").each(function(){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";var _this=$(this);var recheckinput=curform.find("input[name='"+$(this).attr("recheck")+"']");recheckinput.bind("keyup",function(){if(recheckinput.val()==_this.val()&&recheckinput.val()!=""){if(recheckinput.attr("tip")){if(recheckinput.attr("tip")==recheckinput.val()){return false}}_this.trigger("blur")}}).bind("blur",function(){if(recheckinput.val()!=_this.val()&&_this.val()!=""){if(_this.attr("tip")){if(_this.attr("tip")==_this.val()){return false}}_this.trigger("blur")}})});curform.find("[tip]").each(function(){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";var defaultvalue=$(this).attr("tip");var altercss=$(this).attr("altercss");$(this).focus(function(){if($(this).val()==defaultvalue){$(this).val("");if(altercss){$(this).removeClass(altercss)}}}).blur(function(){if($.trim($(this).val())===""){$(this).val(defaultvalue);if(altercss){$(this).addClass(altercss)}}})});curform.find(":checkbox[datatype],:radio[datatype]").each(function(){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";var _this=$(this);var name=_this.attr("name");curform.find("[name='"+name+"']").filter(":checkbox,:radio").bind("click",function(){setTimeout(function(){_this.trigger("blur")},0)})});curform.find("select[datatype][multiple]").bind("click",function(){var _this=$(this); setTimeout(function(){_this.trigger("blur")},0)});Validform.util.usePlugin.call(curform,usePlugin,tiptype,tipSweep,addRule)},usePlugin:function(plugin,tiptype,tipSweep,addRule){var curform=this,plugin=plugin||{};if(curform.find("input[plugin='swfupload']").length&&typeof(swfuploadhandler)!="undefined"){var custom={custom_settings:{form:curform,showmsg:function(msg,type,obj){Validform.util.showmsg.call(curform,msg,tiptype,{obj:curform.find("input[plugin='swfupload']"),type:type,sweep:tipSweep})}}};custom=$.extend(true,{},plugin.swfupload,custom);curform.find("input[plugin='swfupload']").each(function(n){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";$(this).val("");swfuploadhandler.init(custom,n)})}if(curform.find("input[plugin='datepicker']").length&&$.fn.datePicker){plugin.datepicker=plugin.datepicker||{};if(plugin.datepicker.format){Date.format=plugin.datepicker.format;delete plugin.datepicker.format}if(plugin.datepicker.firstDayOfWeek){Date.firstDayOfWeek=plugin.datepicker.firstDayOfWeek;delete plugin.datepicker.firstDayOfWeek}curform.find("input[plugin='datepicker']").each(function(n){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";plugin.datepicker.callback&&$(this).bind("dateSelected",function(){var d=new Date($.event._dpCache[this._dpId].getSelected()[0]).asString(Date.format);plugin.datepicker.callback(d,this)});$(this).datePicker(plugin.datepicker)})}if(curform.find("input[plugin*='passwordStrength']").length&&$.fn.passwordStrength){plugin.passwordstrength=plugin.passwordstrength||{};plugin.passwordstrength.showmsg=function(obj,msg,type){Validform.util.showmsg.call(curform,msg,tiptype,{obj:obj,type:type,sweep:tipSweep})};curform.find("input[plugin='passwordStrength']").each(function(n){if(this.validform_inited=="inited"){return true}this.validform_inited="inited";$(this).passwordStrength(plugin.passwordstrength)})}if(addRule!="addRule"&&plugin.jqtransform&&$.fn.jqTransSelect){if(curform[0].jqTransSelected=="true"){return}curform[0].jqTransSelected="true";var jqTransformHideSelect=function(oTarget){var ulVisible=$(".jqTransformSelectWrapper ul:visible");ulVisible.each(function(){var oSelect=$(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);if(!(oTarget&&oSelect.oLabel&&oSelect.oLabel.get(0)==oTarget.get(0))){$(this).hide()}})};var jqTransformCheckExternalClick=function(event){if($(event.target).parents(".jqTransformSelectWrapper").length===0){jqTransformHideSelect($(event.target))}};var jqTransformAddDocumentListener=function(){$(document).mousedown(jqTransformCheckExternalClick)};if(plugin.jqtransform.selector){curform.find(plugin.jqtransform.selector).filter('input:submit, input:reset, input[type="button"]').jqTransInputButton();curform.find(plugin.jqtransform.selector).filter("input:text, input:password").jqTransInputText();curform.find(plugin.jqtransform.selector).filter("input:checkbox").jqTransCheckBox();curform.find(plugin.jqtransform.selector).filter("input:radio").jqTransRadio();curform.find(plugin.jqtransform.selector).filter("textarea").jqTransTextarea();if(curform.find(plugin.jqtransform.selector).filter("select").length>0){curform.find(plugin.jqtransform.selector).filter("select").jqTransSelect();jqTransformAddDocumentListener()}}else{curform.jqTransform()}curform.find(".jqTransformSelectWrapper").find("li a").click(function(){$(this).parents(".jqTransformSelectWrapper").find("select").trigger("blur")})}},getNullmsg:function(curform){var obj=this;var reg=/[\u4E00-\u9FA5\uf900-\ufa2da-zA-Z\s]+/g;var nullmsg;var label=curform[0].settings.label||".Validform_label";label=obj.siblings(label).eq(0).text()||obj.siblings().find(label).eq(0).text()||obj.parent().siblings(label).eq(0).text()||obj.parent().siblings().find(label).eq(0).text();label=label.replace(/\s(?![a-zA-Z])/g,"").match(reg);label=label?label.join(""):[""];reg=/\{(.+)\|(.+)\}/;nullmsg=curform.data("tipmsg").s||tipmsg.s;if(label!=""){nullmsg=nullmsg.replace(/\{0\|(.+)\}/,label);if(obj.attr("recheck")){nullmsg=nullmsg.replace(/\{(.+)\}/,"");obj.attr("nullmsg",nullmsg);return nullmsg}}else{nullmsg=obj.is(":checkbox,:radio,select")?nullmsg.replace(/\{0\|(.+)\}/,""):nullmsg.replace(/\{0\|(.+)\}/,"$1")}nullmsg=obj.is(":checkbox,:radio,select")?nullmsg.replace(reg,"$2"):nullmsg.replace(reg,"$1");obj.attr("nullmsg",nullmsg);return nullmsg},getErrormsg:function(curform,datatype,recheck){var regxp=/^(.+?)((\d+)-(\d+))?$/,regxp2=/^(.+?)(\d+)-(\d+)$/,regxp3=/(.*?)\d+(.+?)\d+(.*)/,mac=datatype.match(regxp),temp,str;if(recheck=="recheck"){str=curform.data("tipmsg").reck||tipmsg.reck;return str}var tipmsg_w_ex=$.extend({},tipmsg.w,curform.data("tipmsg").w);if(mac[0] in tipmsg_w_ex){return curform.data("tipmsg").w[mac[0]]||tipmsg.w[mac[0]]}for(var name in tipmsg_w_ex){if(name.indexOf(mac[1])!=-1&®xp2.test(name)){str=(curform.data("tipmsg").w[name]||tipmsg.w[name]).replace(regxp3,"$1"+mac[3]+"$2"+mac[4]+"$3");curform.data("tipmsg").w[mac[0]]=str;return str}}return curform.data("tipmsg").def||tipmsg.def },_regcheck:function(datatype,gets,obj,curform){var curform=curform,info=null,passed=false,reg=/\/.+\//g,regex=/^(.+?)(\d+)-(\d+)$/,type=3;if(reg.test(datatype)){var regstr=datatype.match(reg)[0].slice(1,-1);var param=datatype.replace(reg,"");var rexp=RegExp(regstr,param);passed=rexp.test(gets)}else{if(Validform.util.toString.call(Validform.util.dataType[datatype])=="[object Function]"){passed=Validform.util.dataType[datatype](gets,obj,curform,Validform.util.dataType);if(passed===true||passed===undef){passed=true}else{info=passed;passed=false}}else{if(!(datatype in Validform.util.dataType)){var mac=datatype.match(regex),temp;if(!mac){passed=false;info=curform.data("tipmsg").undef||tipmsg.undef}else{for(var name in Validform.util.dataType){temp=name.match(regex);if(!temp){continue}if(mac[1]===temp[1]){var str=Validform.util.dataType[name].toString(),param=str.match(/\/[mgi]*/g)[1].replace("/",""),regxp=new RegExp("\\{"+temp[2]+","+temp[3]+"\\}","g");str=str.replace(/\/[mgi]*/g,"/").replace(regxp,"{"+mac[2]+","+mac[3]+"}").replace(/^\//,"").replace(/\/$/,"");Validform.util.dataType[datatype]=new RegExp(str,param);break}}}}if(Validform.util.toString.call(Validform.util.dataType[datatype])=="[object RegExp]"){passed=Validform.util.dataType[datatype].test(gets)}}}if(passed){type=2;info=obj.attr("sucmsg")||curform.data("tipmsg").r||tipmsg.r;if(obj.attr("recheck")){var theother=curform.find("input[name='"+obj.attr("recheck")+"']:first");if(gets!=theother.val()){passed=false;type=3;info=obj.attr("errormsg")||Validform.util.getErrormsg.call(obj,curform,datatype,"recheck")}}}else{info=info||obj.attr("errormsg")||Validform.util.getErrormsg.call(obj,curform,datatype);if(Validform.util.isEmpty.call(obj,gets)){info=obj.attr("nullmsg")||Validform.util.getNullmsg.call(obj,curform)}}return{passed:passed,type:type,info:info}},regcheck:function(datatype,gets,obj){var curform=this,info=null,passed=false,type=3;if(obj.attr("ignore")==="ignore"&&Validform.util.isEmpty.call(obj,gets)){if(obj.data("cked")){info=""}return{passed:true,type:4,info:info}}obj.data("cked","cked");var dtype=Validform.util.parseDatatype(datatype);var res;for(var eithor=0;eithor=obj.forms.length){return null}if(!(n in obj.objects)){obj.objects[n]=new Validform($(obj.forms[n]).get(),{},true)}return obj.objects[n]},resetStatus:function(){var obj=this;$(obj.forms).each(function(){this.validform_status="normal"});return this},setStatus:function(status){var obj=this;$(obj.forms).each(function(){this.validform_status=status||"posting"});return this},getStatus:function(){var obj=this;var status=$(obj.forms)[0].validform_status;return status},ignore:function(selector){var obj=this;var selector=selector||"[datatype]";$(obj.forms).find(selector).each(function(){$(this).data("dataIgnore","dataIgnore").removeClass("Validform_error")});return this},unignore:function(selector){var obj=this;var selector=selector||"[datatype]";$(obj.forms).find(selector).each(function(){$(this).removeData("dataIgnore")});return this},addRule:function(rule){var obj=this;var rule=rule||[];for(var index=0;index0?top:0);obj.css({left:left}).animate({top:top},{duration:time,queue:false})}function creatMsgbox(){if($("#Validform_msg").length!==0){return false }msgobj=$('
'+tipmsg.tit+'χ
').appendTo("body");msgobj.find("a.Validform_close").click(function(){msgobj.hide();msghidden=true;if(errorobj){errorobj.focus().addClass("Validform_error")}return false}).focus(function(){this.blur()});$(window).bind("scroll resize",function(){!msghidden&&setCenter(msgobj,400)})}$.Showmsg=function(msg){creatMsgbox();Validform.util.showmsg.call(win,msg,1,{})};$.Hidemsg=function(){msgobj.hide();msghidden=true}})(jQuery,window);