-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvchains.min.js
More file actions
1 lines (1 loc) · 4.02 KB
/
Copy pathvchains.min.js
File metadata and controls
1 lines (1 loc) · 4.02 KB
1
var vchains=new function(){var e=function(e,t){this.value=e,this.success=t,this.error=""},t=function(e,t){return function(){return this.error=this.error||e.apply(this,t),this.errorCallback&&this.error&&this.errorCallback(this.error),this}};e.use=function(){if(typeof arguments[0]=="string"){var e=arguments[1];this.prototype[arguments[0]]=t(e,arguments);return}for(var n in arguments[0]){var e=arguments[0][n];this.prototype[n]=t(e,arguments)}},e.prototype.use=function(n,r,i){return this[n]=t(r,arguments),i&&(e.prototype[n]=this[n]),this},e.prototype.onError=function(e){return this.errorCallback=e,this},e.prototype.msg=function(){return this.error||this.success||""},e.prototype.error=function(){return this.error||""},e.prototype.val=function(){return this.value},e.use("invalid",function(e){return e||"Error"}),e.use("is",function(e,t){if(!this.value.match(e))return t||"Bad value"}),e.use("isNot",function(e,t){if(this.value.match(e))return t||"Bad value"}),e.use("isEmail",function(e){if(!this.value.match(/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/))return e||"Bad email"}),e.use("isUrl",function(e){if(!(this.value.match(/^(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?:\w+:\w+@)?(localhost|(?:(?:[-\w\d{1-3}]+\.)+(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|edu|co\.uk|ac\.uk|it|fr|tv|museum|asia|local|travel|[a-z]{2}))|((\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)(\.(\b25[0-5]\b|\b[2][0-4][0-9]\b|\b[0-1]?[0-9]?[0-9]\b)){3}))(?::[\d]{1,5})?(?:(?:(?:\/(?:[-\w~!$+|.,="'\(\)_\*]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?:#(?:[-\w~!$ |\/.,*:;=]|%[a-f\d]{2})*)?$/i)||this.value.length>2083))return e||"Bad URL"}),e.use("isIp",function(e){if(!this.value.match(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/))return e||"Bad IP"}),e.use("isNum",function(e){if(typeof this.value!="string"||!this.value.match(/^-?[0-9]+$/))return e||"Bad numeric string"}),e.use("isAlpha",function(e){if(!this.value.match(/^[a-zA-Z]+$/))return e||"Bad alpha string"}),e.use("isAlphanum",function(e){if(!this.value.match(/^[a-zA-Z0-9]+$/))return e||"Bad alphanumeric string"}),e.use("isInt",function(e){var t=parseFloat(this.value),n=parseInt(this.value,10);if(isNaN(n)||t!=n)return e||"Bad int value"}),e.use("isFloat",function(e){if(v===""||!this.value.match(/^(?:-?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/))return e||"Bad float value"}),e.use("isL",function(e,t){f=parseFloat(this.value);if(isNaN(f)||f<e)return t||"Value too small"}),e.use("isLE",function(e,t){f=parseFloat(this.value);if(isNaN(f)||f<=e)return t||"Value too small"}),e.use("isG",function(e,t){f=parseFloat(this.value);if(isNaN(f)||f>e)return t||"Value too big"}),e.use("isGE",function(e,t){f=parseFloat(this.value);if(isNaN(f)||f>=e)return t||"Value too big"}),e.use("isLen",function(e,t,n){if(this.value.length<e||t!==undefined&&this.value.length>t)return n||"String length not in given range"}),e.use("isEqual",function(e,t){if(this.value!=e)return t||"Values not equal"}),e.use("isIn",function(e,t){if(e.indexOf(this.value)===-1)return t||"Bad value"}),e.use("isNotIn",function(e,t){if(e.indexOf(this.value)!==-1)return t||"Bad value"}),e.use("isCard",function(e){var t=this.value.replace(/[^0-9]+/g,"");if(!t.match(/^(?: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})$/))return;var n,r=0,i=!1;for(var s=t.length-1;s>=0;s--)n=parseInt(t[s],10),i&&(n*=2),r+=n>=10?n%10+1:n,i=!i;if(r%10)return e||"Bad credit card number"}),this.extend=function(t,n){e.prototype[t]=n},this.use=function(t,n){e.use(t,n)},this.validate=function(t,n){return new e(t,n)}};typeof module.exports=="object"&&(module.exports=vchains);