-
Notifications
You must be signed in to change notification settings - Fork 0
/
_v_.min.js
17 lines (17 loc) · 9.31 KB
/
_v_.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* _v_ v0.5.0*/
(function(z,s,A){var g=function(a){if(!(this instanceof g))return new g(a);this.value=a||"";this.separator=" ";this.rule="";this.parsedRules=[];return this},j=g.prototype;j.separate=function(a){this.separator=a;this.rules(this.rule);return this};j.rules=function(a){this.rule=a||"";this.parseRules();return this};j.addRule=function(a){var b=this.parsedRules,c=g().rules(a).parsedRules,d;for(d in c)if(a=c[d])if(a&&b.hasOwnProperty(d)){b[d]=m(b[d]);a=m(a);for(var e=0,h=a.length;e<h;e++)-1===r(b[d],a[e])&&
b[d].push(a[e])}else b[d]=a;else b[d]=a;this.rule=v(this.parsedRules,this.separator);return this};j.delRule=function(a){var b=this.parsedRules;a=g().rules(a).parsedRules;for(var c in a){var d=a[c];if(b.hasOwnProperty(c))if(d===A)delete b[c];else{b[c]=m(b[c]);for(var d=m(d),e=0,h=d.length;e<h;e++){var B=r(b[c],d[e]);~B&&b[c].splice(B,1)}0===b[c].length?delete b[c]:1===b[c].length&&(b[c]=b[c][0])}}this.rule=v(this.parsedRules,this.separator);return this};j.hasRule=function(a){a=g().rules(a).parsedRules;
var b=this.parsedRules,c;for(c in a){var d=a[c];if(!d)if(b.hasOwnProperty(c))continue;else return!1;b[c]=m(b[c]);for(var d=m(d),e=0,h=d.length;e<h;e++)if(-1===r(b[c],d[e]))return!1}return!0};j.parseRules=function(){for(var a=this.rule.split(this.separator),b={},c=this.keys,d=0,e=a.length;d<e;d++){var h=a[d],g,j,l=A;if(c[h])g=c[h],j=h;else for(var n=this.keys_order,t=0,p=n.length;t<p;t++){var u=n[t];if(0===h.indexOf(u)){j=u;l=h.replace(u,"");(h=/^\[(.+)\]$/.exec(l))&&(l=h[1].split(","));g=this.keys[j];
break}}g&&(b[j]=l)}this.parsedRules=b;this.rule=v(b,this.separator);return b};j.validate=function(a){a&&this.rules(a);a=this.parsedRules;for(var b in a)try{if(!this.keys[b].call(this,a[b]))return!1}catch(c){return!1}return!0};j.extend=function(a,b){j.keys[a]=b;j.keys_order.push(a);j.keys_order=this.keys_order.sort(function(a,b){return b.length-a.length});return this};j.keys={};j.keys_order=[];z._v_=g;var C={"*":function(){return 0!==this.value.length},a:function(){return/^[a-z]+$/i.test(this.value)},
a1:function(){return/^[a-z0-9]+$/i.test(this.value)},a_:function(){return/^[a-z_-]+$/i.test(this.value)},a1_:function(){return/^[a-z0-9_-]+$/i.test(this.value)},"@":function(){return/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(this.value)},
"@s":function(){for(var a=this.value.split(","),b=0;b<a.length;b++)if(!g(a[b]).validate("@"))return!1;return!0},ip:function(){return/^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i.test(this.value)},b64:function(){return/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{4})$/.test(this.value)},url:function(){return/^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(this.value)},
"int":function(){return/^\-?[0-9]+$/.test(this.value)},num:function(){return/^[0-9]+$/.test(this.value)},dec:function(){return/^\-?[0-9]*\.?[0-9]+$/.test(this.value)},nat:function(){return/^[0-9]+$/i.test(this.value)},"l=":function(a){if("number"==typeof a||"string"==typeof a)return this.value.length==a;for(var b in a)if(this.value.length==a[b])return!0;return!1},"l>":function(a){return this.value.length>a},"l>=":function(a){return this.value.length>=a},"l<":function(a){return this.value.length<a},
"l<=":function(a){return this.value.length<=a},"lr=":function(a){return this.value.length>=a[0]&&this.value.length<=a[1]},">":function(a){var b=this.value;return g(b).validate("dec")&&parseFloat(b)>parseFloat(a)},">=":function(a){var b=this.value;return g(b).validate("dec")&&parseFloat(b)>=parseFloat(a)},"<":function(a){var b=this.value;return g(b).validate("dec")&&parseFloat(b)<parseFloat(a)},"<=":function(a){var b=this.value;return g(b).validate("dec")&&parseFloat(b)<=parseFloat(a)},"r=":function(a){var b=
this.value;return g(b).validate("dec")&&parseFloat(b)>=parseFloat(a[0])&&parseFloat(b)<=parseFloat(a[1])},"reg=":function(a){return RegExp(a,"i").test(this.value)},"=":function(a){var b=this.value;if("string"==typeof a||"number"==typeof a)return b==a;for(var c=0,d=a.length;c<d;c++)if(0===a[c].indexOf("#")){var e;e=a[c].replace("#","");e=s.getElementById(e);if(!e)break;if(b==e.value)return!0}else if(b==a[c])return!0;return!1},"=#":function(a){var b=this.value;if("string"==typeof a||"number"==typeof a){a=
a.split(" ");var c=s.getElementById(a);return!c?!1:b==c.value}for(var d=0;d<a.length;d++)if((c=s.getElementById(a[d]))&&b==c.value)return!0;return!1},"!=":function(a){a=q(a)?"["+a.join(",")+"]":a;return!g(this.value).validate("="+a)},"!":function(a){if("string"==typeof a||"number"==typeof a)return-1===this.value.toString().indexOf(a.toString());for(var b in a)if(~this.value.toString().indexOf(a[b].toString()))return!1;return!0},c:function(){return/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/.test(this.value)},
cv:function(){return/^4[0-9]{12}(?:[0-9]{3})?$/.test(this.value)},cm:function(){return/^5[1-5][0-9]{14}$/.test(this.value)},ca:function(){return/^3[47][0-9]{13}$/.test(this.value)},cd:function(){return/^6(?:011|5[0-9]{2})[0-9]{12}$/.test(this.value)},"D=":function(a){return!!D(this.value,a)}},w;for(w in C)g().extend(w,C[w]);var E="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),F="Sun Mon Tue Wed Thu Fri Sat".split(" "),G="January February March April May June July August September October November December".split(" "),
H="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),D=function(a,b){var c=(new Date).getFullYear(),d=0,e=1,h=0,g=0,j=0,l=-1,n=-1,t=-1,p=-1,u=-1,m=-1,r=-1,q="m",s="h",k=1,f="",v=a.replace(/\s+/g," ");b=b.replace(/\s+/g," ");for(var x=0,w=b.length;x<w;x++){var y=b.charAt(x);switch(y){case "Y":f+="(\\d{4})";l=k++;break;case "y":f+="(\\d{2})";l=k++;break;case "M":case "m":f+="(\\d{1,2})";n=k++;q="m";break;case "N":f+="("+G.join("|")+")";n=k++;q="N";break;case "n":f+="("+H.join("|")+")";n=k++;
q="n";break;case "D":case "d":f+="(\\d{1,2})";t=k++;break;case "W":f+="("+E.join("|")+")";k++;break;case "w":f+="("+F.join("|")+")";k++;break;case "H":case "h":f+="(\\d{1,2})";p=k++;s="h";break;case "R":case "r":f+="(\\d{1,2})";p=k++;s="r";break;case "I":case "i":f+="(\\d{1,2})";u=k++;break;case "S":case "s":f+="(\\d{1,2})";m=k++;break;case "A":case "a":f+="(AM|am|PM|pm)";r=k++;break;default:f+="^"==y?b.charAt(++x):y}}k=v.match(RegExp(f));if(!k)return null;-1<l&&(c=parseInt(k[l],10),c=50>c?c+2E3:
100>c?c+1900:c);if(-1<n)switch(q){case "m":d=parseInt(k[n],10)-1;if(11<d)return null;break;case "N":d=parseInt(__monthNumbers[k[n]],10);if(isNaN(d))return null;break;case "n":if(d=parseInt(__shortMonthNumbers[k[n]],10),isNaN(d))return null}if(-1<t){e=parseInt(k[t],10);if(!(l=1>e))l=1==d&&(0===c%4&&0!==c%100||0===c%400)?29:[31,28,31,30,31,30,31,31,30,31,30,31][d],l=e>l;if(l)return null}if(-1<p&&(h=parseInt(k[p],10),"h"==s&&(0===h||12<h)||23<h)||-1<u&&(g=parseInt(k[u],10),59<g)||-1<m&&(j=parseInt(k[m],
10),59<j))return null;if(-1<r&&(p=k[r],("pm"==p||"PM"==p)&&12>h))h+=12;return new Date(c,d,e,h,g,j)},q=function(a){return"[object Array]"==Object.prototype.toString.call(a)},r=function(a,b){for(var c=-1,d=a?a.length:0;++c<d;)if(a[c]===b)return c;return-1};z.__inArray=r;var m=function(a){return!q(a)?[a]:a},v=function(a,b){var c=b=b||" ",d;for(d in a){var e=a[d];if(q(e)){for(var h=[],g=0,j=e.length;g<j;g++)e[g]&&h.push(e[g]);e=h&&1<h.length?h:h[0]}c=e?q(e)?c+(d+"["+e.join(",")+"]"+b):c+(d+e+b):c+(d+
b)}return c=c.substr(b.length,c.length-2*b.length)}})(window,document);