-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjvalidate.min.js
4 lines (4 loc) · 1.85 KB
/
jvalidate.min.js
1
2
3
4
(function(a,j,h){a.JValidate=function(c,b){this.element=c;this.settings=a.extend({},a.JValidate.defaults,b);this.initialize()};a.JValidate.defaults={prefix:"",defaultSuccess:h,defaultError:h,defaultRules:{required:{validateFunction:function(a){return a.length},errorCallback:a.noop,successCallback:a.noop},email:{validateFunction:function(a){return/^([a-z0-9_\.\-]+)@([\da-z\.\-]+)\.([a-z\.]{2,6})$/.test(a)},errorCallback:a.noop,successCallback:a.noop},url:{validateFunction:function(a){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(a)},
errorCallback:a.noop,successCallback:a.noop},numeric:{validateFunction:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},errorCallback:a.noop,successCallback:a.noop}}};a.JValidate.prototype={initialize:function(){this.reloadRules();return this},addRule:function(c,b,d,e){var i={};i[c]={validateFunction:b||function(){return!0},errorCallback:d||this.settings.defaultError||a.noop,successCallback:e||this.settings.defaultSuccess||a.noop};this._rules=a.extend(i,this._rules);return this},validate:function(c){var b=
this,d=[],e=[];a(this.element).find("input, textarea").each(function(c,g){for(var f in b._rules)a(g).hasClass(b.settings.prefix+f)&&(b._rules[f].validateFunction(a(this).val())?(e.push(a(g)),b._rules[f].successCallback(this)):(d.push(a(g)),b._rules[f].errorCallback(this)))});a.isFunction(c)&&c(d,e);return this},getRules:function(){return this._rules},reloadRules:function(){this._rules=this.settings.defaultRules;for(var c in this._rules)this._rules[c].errorCallback=this.settings.defaultError||a.noop,
this._rules[c].successCallback=this.settings.defaultSuccess||a.noop;return this},setErrorCallback:function(c,b){a.isFunction(b)&&(this._rules[c].errorCallback=b);return this},setSuccessCallback:function(c,b){a.isFunction(b)&&(this._rules[c].successCallback=b);return this}}})(jQuery,this);