diff --git a/jquery-validator.js b/jquery-validator.js index b2bcfce..a7e031f 100644 --- a/jquery-validator.js +++ b/jquery-validator.js @@ -1,6 +1,6 @@ /************************************** @Name: jQuery-Validator 基于jQuery的表单验证框架 - @Version: 1.3.1 milestone + @Version: 1.3.2 @Author: Ready @Date: 2015-02-25 @Documentation: http://www.365mini.com/page/jquery-validator-quickstart.htm @@ -37,7 +37,7 @@ }, fn = V.fn = V.prototype = { // 版本号 - version: "1.3.1", + version: "1.3.2", constructor: V, diff --git a/jquery-validator.min.js b/jquery-validator.min.js index 1cdf3e3..d176cf3 100644 --- a/jquery-validator.min.js +++ b/jquery-validator.min.js @@ -1,10 +1,10 @@ /************************************** @Name: jQuery-Validator 基于jQuery的表单验证框架 - @Version: 1.3.1 milestone + @Version: 1.3.2 @Author: Ready @Documentation: http://www.365mini.com/page/jquery-validator-quickstart.htm @Copyright: CodePlayer( Ready ) @Email: CodePlayer360@gmail.com @Licence: https://www.apache.org/licenses/LICENSE-2.0.html */ -!function(a,b){var d,e,f,g,c=b&&b.console;return"undefined"==typeof jQuery||a!==jQuery?(c&&c.log("jQuery must be initialized before loading the Validator."),void 0):(d=function(b){if(!(this instanceof d))return new d(b);if(b||(b="v"),!a.fn[b]){var c=this;a.fn[b]=function(a,b){return c.execute(this,a,b)}}},e=d.cache={},f=d.log=function(){if(c){for(var a=0;a2&&(g=["?",g[0]])):g=["?",null],e[c.rule.format]=g),d.debug&&f("idcard pattern:",g),!a||"?"==g[0]&&15!=a.length&&18!=a.length||a.length!=g[0])return!1;if(h=18==a.length){for(i=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],j=0,k=0;kq.getTime())return!1;if(r=q.getFullYear()-p.getFullYear(),q.setFullYear(q.getFullYear()-r),p.getTime()>q.getTime()&&r--,s=c.label,c.age=r,c.label="身份证年龄",this.validator.range.call(this,r,g[1],c)===!1)return!1;c.label=s}return p}},validator:{required:function(b,c,d){var f,g,e=d.$dom;if(e&&e.length&&(g=e[0],g.nodeName,null==g.checked||"checkbox"!=g.type&&"radio"!=g.type||(f=!0,d.actual=b=e.filter(":checked").length)),!b){if(c&&(!a.isFunction(c)||(c=c.call(this,b,d))))return this.sendError(f?"checked":"",b,"required",d),!1;d._stop=!0}},format:function(a,b,c){var e=d.util.parseFormat(b),f=this.formatter[c.child=e[0]];if(f)return a=c.formatResult=f.call(this,a,e[1],c),a===!1&&this.sendError(b,a,e[1],c),a;throw"Unsupported format validator:"+e[0]},text:function(b,c,d){var e=a.type(c);switch(e){case"string":if(c!=b)return this.sendError("==",b,c,d),!1;break;case"regexp":if(!c.test(b))return this.sendError("regexp",b,c,d),!1;break;case"function":if(c.call(this,b,d)===!1)return this.sendError("function",b,c,d),!1;break;default:throw"Unexpected text validator:"+c}},length:function(a,b,c){return this.validator.range.call(this,c.value.length,b,c)},range:function(a,b,c){var f,g,e=d.util.parseIntervalPattern(b);if(e.equals){if(a!=e.min)return this.sendError("==",a,e.min,c),!1}else{if(e.min&&(f=a>e.min||">="==e.left&&e.min==a,!f))return this.sendError(e.left,a,e.min,c),f;if(e.max&&(g=a=":"{label}必须大于或等于{expected}!",">":"{label}必须大于{expected}!","<=":"{label}必须小于或等于{expected}!","<":"{label}必须小于{expected}!","length.==":"{label}的长度必须等于{expected}!","length.>=":"{label}的长度必须大于或等于{expected}!","length.>":"{label}的长度必须大于{expected}!","length.<=":"{label}的长度必须小于或等于{expected}!","length.<":"{label}的长度必须小于{expected}!","format.number":"{label}必须是有效的整数!","format.number/money":"{label}必须是整数或最多保留两位的小数!","format.number/double":"{label}必须是有效的整数或小数!","format.date":'{label}必须为"{dateFormat}"格式的有效时间!',file:"{label}的格式不正确,必须为{expected}等格式!","default":"{label}的格式不正确!"},setMessage:function(a,b,c){c||(c=!(this instanceof d));var e=c?g.messages:this.messages;if(c||e!=g.messages||(this.messages=e={}),"object"==typeof a)for(i in a)e[i]=a[i];else e[a]=b},getMessage:function(b){var e,f,h,c=[b.message,b.rule.message,this.messages,g.messages];for(h in c){if(f=e=c[h],e===!1)return f;if(null!=e){if("object"==typeof e&&(f=e[b.validator+"."+b.trigger],null==f&&(!b.child||null==(f=e[b.validator+"."+b.child]))&&null==(f=e[b.validator])&&(f=e[b.trigger])),f===!1)return f;if(null!=f)break}}return f&&a.isFunction(f)&&(f=f.call(null,b)),f!==!1&&(f||(f=this.messages["default"]||g.messages["default"]),f&&(f=d.util.parseMessage(f,b,this))),f},labels:{},setLabel:function(a,b,c){c||(c=!(this instanceof d));var e=c?g.labels:this.labels;if(c||e!=g.labels||(this.labels=e={}),"object"==typeof a)for(i in a)e[i]=a[i];else e[a]=b},getLabel:function(a,b){if(a||(a=b.prop("name")),null!=a){var d=this.labels[a]||g.labels[a];if(null==d&&b&&b.length&&(d=b.attr("label")||b.prev("label").text()))return d}return""}},d.util={parseFormat:function(a){var b=a.indexOf("/"),c=[a,""];return b>0&&(c[0]=a.substring(0,b),c[1]=a.substr(b+1)),c},parseIntervalPattern:function(a){if(!e[a]){if(e.__interval||(e.__interval=/^([\[\(])(-?\d+(\.\d+)?)?(,)?(-?\d+(\.\d+)?)?([\]\)])$/),!e.__interval.test(a)||!RegExp.$2&&!RegExp.$4)throw"Unexpected interval pattern:"+a;var b={min:RegExp.$2,max:RegExp.$5};RegExp.$4==RegExp.$5?b.equals=!0:(b.left="["==RegExp.$1?">=":">",b.right="]"==RegExp.$7?"<=":"<"),e[a]=b}return e[a]},parseMessage:function(b,c,d){var f=c.$relatedDoms;return b.replace(e.__message||(e.__message=/\{([^}]+)\}/g),function(b,e){var h,i,g=e.charAt(0);return"#"==g||"$"==g?(i=e.substr(1),h=f&&f[i]?d.getLabel(null,f[i],c):d.getLabel(null,a("#"==g?"#"+i:"[name='"+i+"']"),c)):h=c[e],h||(h=""),h})},pushDomContext:function(a,b,c){var d=c.$relatedDoms||(c.$relatedDoms=[]);a||(a=b.prop("name")),d.push(b),a&&(d[a]=b)}},g.define({username:{pre:"trimAll,lower,flush",text:/^[a-z][a-z0-9_]{5,15}$/i,message:"{label}必须是英文字母、数字和下划线组成的6~16位字符,并且必须以字母开头!"},password:{length:"[6,16]"},age:{format:"number",range:"[18,100]"},"int":{format:"number"},"int+":{format:"number",range:"(0,)"},money:{format:"number/money"},"money+":{format:"number/money",range:"(0,)"},date:{format:"date"},datetime:{format:"date/datetime"},phoneCode:{format:"number",length:"[6]"},imageCode:{length:"[4]"},required:{},cellphone:!0,email:!0,idcard:{pre:"upper,flush",format:"idcard/18:[18,]"},image:"jpg|jpeg|gif|png|bmp"}),(b||(b="undefined"!=typeof window?window:this))&&(b.V=d),void 0)}(jQuery,window); \ No newline at end of file +!function(a,b){var d,e,f,g,c=b&&b.console;return"undefined"==typeof jQuery||a!==jQuery?(c&&c.log("jQuery must be initialized before loading the Validator."),void 0):(d=function(b){if(!(this instanceof d))return new d(b);if(b||(b="v"),!a.fn[b]){var c=this;a.fn[b]=function(a,b){return c.execute(this,a,b)}}},e=d.cache={},f=d.log=function(){if(c){for(var a=0;a2&&(g=["?",g[0]])):g=["?",null],e[c.rule.format]=g),d.debug&&f("idcard pattern:",g),!a||"?"==g[0]&&15!=a.length&&18!=a.length||a.length!=g[0])return!1;if(h=18==a.length){for(i=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],j=0,k=0;kq.getTime())return!1;if(r=q.getFullYear()-p.getFullYear(),q.setFullYear(q.getFullYear()-r),p.getTime()>q.getTime()&&r--,s=c.label,c.age=r,c.label="身份证年龄",this.validator.range.call(this,r,g[1],c)===!1)return!1;c.label=s}return p}},validator:{required:function(b,c,d){var f,g,e=d.$dom;if(e&&e.length&&(g=e[0],g.nodeName,null==g.checked||"checkbox"!=g.type&&"radio"!=g.type||(f=!0,d.actual=b=e.filter(":checked").length)),!b){if(c&&(!a.isFunction(c)||(c=c.call(this,b,d))))return this.sendError(f?"checked":"",b,"required",d),!1;d._stop=!0}},format:function(a,b,c){var e=d.util.parseFormat(b),f=this.formatter[c.child=e[0]];if(f)return a=c.formatResult=f.call(this,a,e[1],c),a===!1&&this.sendError(b,a,e[1],c),a;throw"Unsupported format validator:"+e[0]},text:function(b,c,d){var e=a.type(c);switch(e){case"string":if(c!=b)return this.sendError("==",b,c,d),!1;break;case"regexp":if(!c.test(b))return this.sendError("regexp",b,c,d),!1;break;case"function":if(c.call(this,b,d)===!1)return this.sendError("function",b,c,d),!1;break;default:throw"Unexpected text validator:"+c}},length:function(a,b,c){return this.validator.range.call(this,c.value.length,b,c)},range:function(a,b,c){var f,g,e=d.util.parseIntervalPattern(b);if(e.equals){if(a!=e.min)return this.sendError("==",a,e.min,c),!1}else{if(e.min&&(f=a>e.min||">="==e.left&&e.min==a,!f))return this.sendError(e.left,a,e.min,c),f;if(e.max&&(g=a=":"{label}必须大于或等于{expected}!",">":"{label}必须大于{expected}!","<=":"{label}必须小于或等于{expected}!","<":"{label}必须小于{expected}!","length.==":"{label}的长度必须等于{expected}!","length.>=":"{label}的长度必须大于或等于{expected}!","length.>":"{label}的长度必须大于{expected}!","length.<=":"{label}的长度必须小于或等于{expected}!","length.<":"{label}的长度必须小于{expected}!","format.number":"{label}必须是有效的整数!","format.number/money":"{label}必须是整数或最多保留两位的小数!","format.number/double":"{label}必须是有效的整数或小数!","format.date":'{label}必须为"{dateFormat}"格式的有效时间!',file:"{label}的格式不正确,必须为{expected}等格式!","default":"{label}的格式不正确!"},setMessage:function(a,b,c){c||(c=!(this instanceof d));var e=c?g.messages:this.messages;if(c||e!=g.messages||(this.messages=e={}),"object"==typeof a)for(i in a)e[i]=a[i];else e[a]=b},getMessage:function(b){var e,f,h,c=[b.message,b.rule.message,this.messages,g.messages];for(h in c){if(f=e=c[h],e===!1)return f;if(null!=e){if("object"==typeof e&&(f=e[b.validator+"."+b.trigger],null==f&&(!b.child||null==(f=e[b.validator+"."+b.child]))&&null==(f=e[b.validator])&&(f=e[b.trigger])),f===!1)return f;if(null!=f)break}}return f&&a.isFunction(f)&&(f=f.call(null,b)),f!==!1&&(f||(f=this.messages["default"]||g.messages["default"]),f&&(f=d.util.parseMessage(f,b,this))),f},labels:{},setLabel:function(a,b,c){c||(c=!(this instanceof d));var e=c?g.labels:this.labels;if(c||e!=g.labels||(this.labels=e={}),"object"==typeof a)for(i in a)e[i]=a[i];else e[a]=b},getLabel:function(a,b){if(a||(a=b.prop("name")),null!=a){var d=this.labels[a]||g.labels[a];if(null==d&&b&&b.length&&(d=b.attr("label")||b.prev("label").text()))return d}return""}},d.util={parseFormat:function(a){var b=a.indexOf("/"),c=[a,""];return b>0&&(c[0]=a.substring(0,b),c[1]=a.substr(b+1)),c},parseIntervalPattern:function(a){if(!e[a]){if(e.__interval||(e.__interval=/^([\[\(])(-?\d+(\.\d+)?)?(,)?(-?\d+(\.\d+)?)?([\]\)])$/),!e.__interval.test(a)||!RegExp.$2&&!RegExp.$4)throw"Unexpected interval pattern:"+a;var b={min:RegExp.$2,max:RegExp.$5};RegExp.$4==RegExp.$5?b.equals=!0:(b.left="["==RegExp.$1?">=":">",b.right="]"==RegExp.$7?"<=":"<"),e[a]=b}return e[a]},parseMessage:function(b,c,d){var f=c.$relatedDoms;return b.replace(e.__message||(e.__message=/\{([^}]+)\}/g),function(b,e){var h,i,g=e.charAt(0);return"#"==g||"$"==g?(i=e.substr(1),h=f&&f[i]?d.getLabel(null,f[i],c):d.getLabel(null,a("#"==g?"#"+i:"[name='"+i+"']"),c)):h=c[e],h||(h=""),h})},pushDomContext:function(a,b,c){var d=c.$relatedDoms||(c.$relatedDoms=[]);a||(a=b.prop("name")),d.push(b),a&&(d[a]=b)}},g.define({username:{pre:"trimAll,lower,flush",text:/^[a-z][a-z0-9_]{5,15}$/i,message:"{label}必须是英文字母、数字和下划线组成的6~16位字符,并且必须以字母开头!"},password:{length:"[6,16]"},age:{format:"number",range:"[18,100]"},"int":{format:"number"},"int+":{format:"number",range:"(0,)"},money:{format:"number/money"},"money+":{format:"number/money",range:"(0,)"},date:{format:"date"},datetime:{format:"date/datetime"},phoneCode:{format:"number",length:"[6]"},imageCode:{length:"[4]"},required:{},cellphone:!0,email:!0,idcard:{pre:"upper,flush",format:"idcard/18:[18,]"},image:"jpg|jpeg|gif|png|bmp"}),(b||(b="undefined"!=typeof window?window:this))&&(b.V=d),void 0)}(jQuery,window); \ No newline at end of file