| 123456789101112 |
- /**
- * BootstrapValidator (https://github.com/nghuuphuoc/bootstrapvalidator)
- *
- * A jQuery plugin to validate form fields. Use with Bootstrap 3
- *
- * @version v0.3.2-dev
- * @author https://twitter.com/nghuuphuoc
- * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
- * @license MIT
- */
- !function(a){var b=function(c,d){this.$form=a(c),this.options=a.extend({},b.DEFAULT_OPTIONS,d),this.dfds={},this.results={},this.invalidField=null,this.$submitButton=null,this._init(),this.STATUS_NOT_VALIDATED="NOT_VALIDATED",this.STATUS_VALIDATING="VALIDATING",this.STATUS_INVALID="INVALID",this.STATUS_VALID="VALID"};b.DEFAULT_OPTIONS={elementClass:"bootstrap-validator-form",message:"This value is not valid",feedbackIcons:{valid:null,invalid:null,validating:null},submitButtons:'button[type="submit"]',submitHandler:null,live:"enabled",fields:null},b.prototype={constructor:b,_init:function(){if(null!=this.options.fields){var b=this;this.$form.attr("novalidate","novalidate").addClass(this.options.elementClass).on("submit.bootstrapValidator",function(a){a.preventDefault(),b.validate()}).find(this.options.submitButtons).on("click",function(){b.$submitButton=a(this)});for(var c in this.options.fields)this._initField(c);this._setLiveValidating()}},_initField:function(b){if(null!=this.options.fields[b]&&null!=this.options.fields[b].validators){this.dfds[b]={},this.results[b]={};var c=this.getFieldElements(b);if(null==c)return delete this.options.fields[b],void delete this.dfds[b];var d=a(c[0]),e=d.parents(".form-group"),f=this._getMessageContainer(d);d.data("bootstrapValidator.messageContainer",f);for(var g in this.options.fields[b].validators)a.fn.bootstrapValidator.validators[g]?(this.results[b][g]=this.STATUS_NOT_VALIDATED,a("<small/>").css("display","none").attr("data-bs-validator",g).html(this.options.fields[b].validators[g].message||this.options.message).addClass("help-block").appendTo(f)):delete this.options.fields[b].validators[g];if(this.options.feedbackIcons){e.addClass("has-feedback");var h=a("<i/>").css("display","none").addClass("form-control-feedback").insertAfter(a(c[c.length-1]));0==e.find("label").length&&h.css("top",0)}null==this.options.fields[b].enabled&&(this.options.fields[b].enabled=!0);var i=this,j=c.attr("type"),k="radio"==j||"checkbox"==j||"SELECT"==c[0].tagName?"change":"keyup";c.on(k,function(){i.updateStatus(d,i.STATUS_NOT_VALIDATED,null)})}},_getMessageContainer:function(a){var b=a.parent();if(b.hasClass("form-group"))return b;var c=b.attr("class");if(!c)return this._getMessageContainer(b);c=c.split(" ");for(var d=c.length,e=0;d>e;e++)if(/^col-(xs|sm|md|lg)-\d+$/.test(c[e])||/^col-(xs|sm|md|lg)-offset-\d+$/.test(c[e]))return b;return this._getMessageContainer(b)},_setLiveValidating:function(){if("enabled"==this.options.live){var a=this;for(var b in this.options.fields)!function(b){var c=a.getFieldElements(b);if(c){var d=c.attr("type"),e="radio"==d||"checkbox"==d||"SELECT"==c[0].tagName?"change":"keyup";c.on(e,function(){a.validateField(b)})}}(b)}},_disableSubmitButtons:function(a){a?"disabled"!=this.options.live&&this.$form.find(this.options.submitButtons).attr("disabled","disabled"):this.$form.find(this.options.submitButtons).removeAttr("disabled")},_submit:function(){return this.isValid()?(this._disableSubmitButtons(!0),void(this.options.submitHandler&&"function"==typeof this.options.submitHandler?this.options.submitHandler.call(this,this,this.$form,this.$submitButton):this.$form.off("submit.bootstrapValidator").submit())):("submitted"==this.options.live&&(this.options.live="enabled",this._setLiveValidating()),void(this.invalidField&&this.getFieldElements(this.invalidField).focus()))},getFieldElements:function(a){var b=this.$form.find('[name="'+a+'"]');return 0==b.length?null:b},validate:function(){if(!this.options.fields)return this;this._disableSubmitButtons(!0);for(var a in this.options.fields)this.validateField(a);return this._submit(),this},validateField:function(b){if(this.options.fields[b].enabled){var c,d,e=this,f=this.getFieldElements(b),g=a(f[0]),h=this.options.fields[b].validators;if(1==f.length&&f.is(":disabled"))return delete this.options.fields[b],void delete this.dfds[b];for(c in h)this.dfds[b][c]&&this.dfds[b][c].reject(),this.results[b][c]!=this.STATUS_VALID&&this.results[b][c]!=this.STATUS_INVALID&&(this.results[b][c]=this.STATUS_VALIDATING,d=a.fn.bootstrapValidator.validators[c].validate(this,g,h[c]),"object"==typeof d?(this.updateStatus(g,this.STATUS_VALIDATING,c),this.dfds[b][c]=d,d.done(function(a,c){delete e.dfds[b][c],e.updateStatus(g,a?e.STATUS_VALID:e.STATUS_INVALID,c),a&&"disabled"==e.options.live&&e._submit()})):"boolean"==typeof d&&this.updateStatus(g,d?this.STATUS_VALID:this.STATUS_INVALID,c))}},isValid:function(){var a,b;for(a in this.results)if(this.options.fields[a].enabled)for(b in this.results[a]){if(this.results[a][b]==this.STATUS_NOT_VALIDATED||this.results[a][b]==this.STATUS_VALIDATING)return!1;if(this.results[a][b]==this.STATUS_INVALID)return this.invalidField=a,!1}return!0},updateStatus:function(b,c,d){var e="string"==typeof b?this.getFieldElements(b):b,f=this,b=e.attr("name"),g=e.parents(".form-group"),h=e.data("bootstrapValidator.messageContainer"),i=h.find(".help-block[data-bs-validator]");if(d)this.results[b][d]=c;else for(var j in this.options.fields[b].validators)this.results[b][j]=c;switch(c){case this.STATUS_VALIDATING:this._disableSubmitButtons(!0),g.removeClass("has-success").removeClass("has-error"),d?i.filter('.help-block[data-bs-validator="'+d+'"]').hide():i.hide(),h.find(".form-control-feedback").removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();break;case this.STATUS_INVALID:this._disableSubmitButtons(!0),g.removeClass("has-success").addClass("has-error"),d?i.filter('[data-bs-validator="'+d+'"]').show():i.show(),h.find(".form-control-feedback").removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();break;case this.STATUS_VALID:d?i.filter('[data-bs-validator="'+d+'"]').hide():i.hide(),0==i.filter(function(){var c=a(this).css("display"),d=a(this).attr("data-bs-validator");return"block"==c||f.results[b][d]!=f.STATUS_VALID}).length&&(this._disableSubmitButtons(!1),g.removeClass("has-error").addClass("has-success"),h.find(".form-control-feedback").removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.valid).show());break;case this.STATUS_NOT_VALIDATED:default:this._disableSubmitButtons(!1),g.removeClass("has-success").removeClass("has-error"),d?i.filter('.help-block[data-bs-validator="'+d+'"]').hide():i.hide(),h.find(".form-control-feedback").removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide()}return this},resetForm:function(a){var b,c,d;for(b in this.options.fields)this.dfds[b]={},this.results[b]={},c=this.getFieldElements(b),this.updateStatus(c,this.STATUS_NOT_VALIDATED,null),a&&(d=c.attr("type"),"radio"==d||"checkbox"==d?c.removeAttr("checked").removeAttr("selected"):c.val(""));return this.invalidField=null,this.$submitButton=null,this._disableSubmitButtons(!1),this},enableFieldValidators:function(a,b){return this.options.fields[a].enabled=b,this.updateStatus(a,this.STATUS_NOT_VALIDATED,null),this}},a.fn.bootstrapValidator=function(c){return this.each(function(){var d=a(this),e=d.data("bootstrapValidator");e||d.data("bootstrapValidator",e=new b(this,c)),"string"==typeof c&&e[c]()})},a.fn.bootstrapValidator.validators={},a.fn.bootstrapValidator.Constructor=b}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.between={validate:function(a,b,c){var d=b.val();return""==d?!0:(d=parseFloat(d),c.inclusive===!0?d>c.min&&d<c.max:d>=c.min&&d<=c.max)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.callback={validate:function(b,c,d){var e=c.val();if(d.callback&&"function"==typeof d.callback){var f=new a.Deferred;return f.resolve(d.callback.call(this,e,b),"callback"),f}return!0}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.choice={validate:function(a,b,c){var d=a.getFieldElements(b.attr("name")).filter(":checked").length;return c.min&&d<c.min||c.max&&d>c.max?!1:!0}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.creditCard={validate:function(a,b){var c=b.val();if(""==c)return!0;if(/[^0-9-\s]+/.test(c))return!1;c=c.replace(/\D/g,"");for(var d=0,e=0,f=!1,g=c.length,h=g-1;h>=0;h--)e=parseInt(c.charAt(h),10),f&&(e*=2)>9&&(e-=9),d+=e,f=!f;return d%10==0}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.date={validate:function(a,b,c){var d=b.val();if(""==d)return!0;c.format=c.format||"MM/DD/YYYY";var e=-1!=c.format.indexOf("/")?"/":-1!=c.format.indexOf("-")?"-":null;if(null==e)return!1;var f,g,h,i,j=null,k=null;switch(!0){case"/"==e&&(i=d.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/i))&&"YYYY/DD/MM"==c.format:case"-"==e&&(i=d.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/i))&&"YYYY-DD-MM"==c.format:h=i[1],g=i[2],f=i[3];break;case"/"==e&&(i=d.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/i))&&"DD/MM/YYYY"==c.format:case"-"==e&&(i=d.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/i))&&"DD-MM-YYYY"==c.format:g=i[1],f=i[2],h=i[3];break;case"/"==e&&(i=d.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/i))&&"YYYY/MM/DD"==c.format:case"-"==e&&(i=d.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/i))&&"YYYY-MM-DD"==c.format:h=i[1],f=i[2],g=i[3];break;case"/"==e&&(i=d.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/i))&&"MM/DD/YYYY"==c.format:case"-"==e&&(i=d.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/i))&&"MM-DD-YYYY"==c.format:f=i[1],g=i[2],h=i[3];break;case"/"==e&&(i=d.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"YYYY/DD/MM h:m A"==c.format:case"-"==e&&(i=d.match(/^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"YYYY-DD-MM h:m A"==c.format:h=i[1],g=i[2],f=i[3],k=i[4],j=i[5];break;case"/"==e&&(i=d.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"DD/MM/YYYY h:m A"==c.format:case"-"==e&&(i=d.match(/^(\d{1,2})-(\d{1,2})-(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"DD-MM-YYYY h:m A"==c.format:g=i[1],f=i[2],h=i[3],k=i[4],j=i[5];break;case"/"==e&&(i=d.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"YYYY/MM/DD h:m A"==c.format:case"-"==e&&(i=d.match(/^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"YYYY-MM-DD h:m A"==c.format:h=i[1],f=i[2],g=i[3],k=i[4],j=i[5];break;case"/"==e&&(i=d.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"MM/DD/YYYY h:m A"==c.format:case"-"==e&&(i=d.match(/^(\d{1,2})-(\d{1,2})-(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i))&&"MM-DD-YYYY h:m A"==c.format:f=i[1],g=i[2],h=i[3],k=i[4],j=i[5];break;default:return!1}if(k&&j&&(k=parseInt(k,10),j=parseInt(j,10),1>k||k>12||0>j||j>59))return!1;if(g=parseInt(g,10),f=parseInt(f,10),h=parseInt(h,10),1e3>h||h>9999||0==f||f>12)return!1;var l=[31,28,31,30,31,30,31,31,30,31,30,31];return(h%400==0||h%100!=0&&h%4==0)&&(l[1]=29),g>0&&g<=l[f-1]}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.different={validate:function(a,b,c){var d=b.val();if(""==d)return!0;var e=a.getFieldElements(c.field);return null==e?!0:d!=e.val()?(a.updateStatus(e,a.STATUS_VALID,"different"),!0):!1}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.digits={validate:function(a,b){var c=b.val();return""==c?!0:/^\d+$/.test(c)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.emailAddress={validate:function(a,b){var c=b.val();if(""==c)return!0;var d=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return d.test(c)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.greaterThan={validate:function(a,b,c){var d=b.val();return""==d?!0:(d=parseFloat(d),c.inclusive===!0?d>c.value:d>=c.value)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.hexColor={validate:function(a,b){var c=b.val();return""==c?!0:/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(c)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.identical={validate:function(a,b,c){var d=b.val();if(""==d)return!0;var e=a.getFieldElements(c.field);return null==e?!0:d==e.val()?(a.updateStatus(e,a.STATUS_VALID,"identical"),!0):!1}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.lessThan={validate:function(a,b,c){var d=b.val();return""==d?!0:(d=parseFloat(d),c.inclusive===!0?d<c.value:d<=c.value)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.notEmpty={validate:function(b,c){var d=c.attr("type");return"radio"==d||"checkbox"==d?b.getFieldElements(c.attr("name")).filter(":checked").length>0:""!=a.trim(c.val())}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.regexp={validate:function(a,b,c){var d=b.val();return""==d?!0:c.regexp.test(d)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.remote={validate:function(b,c,d){var e=c.val();if(""==e)return!0;var f=c.attr("name"),g=d.data;null==g&&(g={}),"function"==typeof g&&(g=g.call(this,b)),g[f]=e;var h=new a.Deferred,i=a.ajax({type:"POST",url:d.url,dataType:"json",data:g});return i.then(function(a){h.resolve(a.valid===!0||"true"===a.valid,"remote")}),h.fail(function(){i.abort()}),h}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.stringLength={validate:function(b,c,d){var e=c.val();if(""==e)return!0;var f=a.trim(e).length;return d.min&&f<d.min||d.max&&f>d.max?!1:!0}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.uri={validate:function(a,b){var c=b.val();if(""==c)return!0;var d=new RegExp("^(?:(?:https?|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?!10(?:\\.\\d{1,3}){3})(?!127(?:\\.\\d{1,3}){3})(?!169\\.254(?:\\.\\d{1,3}){2})(?!192\\.168(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/[^\\s]*)?$","i");return d.test(c)}}}(window.jQuery),function(a){a.fn.bootstrapValidator.validators.zipCode={validate:function(a,b,c){var d=b.val();if(""==d||!c.country)return!0;switch(c.country.toUpperCase()){case"DK":return/^(DK(-|\s)?)?\d{4}$/i.test(d);case"SE":return/^(S-)?\d{3}\s?\d{2}$/i.test(d);case"US":default:return/^\d{5}([\-]\d{4})?$/.test(d)}}}}(window.jQuery);
|