| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598 |
- /**
- * BootstrapValidator (https://github.com/nghuuphuoc/bootstrapvalidator)
- *
- * A jQuery plugin to validate form fields. Use with Bootstrap 3
- *
- * @version v0.3.2
- * @author https://twitter.com/nghuuphuoc
- * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
- * @license MIT
- */
- (function($) {
- var BootstrapValidator = function(form, options) {
- this.$form = $(form);
- this.options = $.extend({}, BootstrapValidator.DEFAULT_OPTIONS, options);
- this.dfds = {}; // Array of deferred
- this.results = {}; // Validating results
- this.invalidField = null; // First invalid field
- this.$submitButton = null; // The submit button which is clicked to submit form
- this._init();
- this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED';
- this.STATUS_VALIDATING = 'VALIDATING';
- this.STATUS_INVALID = 'INVALID';
- this.STATUS_VALID = 'VALID';
- };
- // The default options
- BootstrapValidator.DEFAULT_OPTIONS = {
- // The form CSS class
- elementClass: 'bootstrap-validator-form',
- // Default invalid message
- message: 'This value is not valid',
- // Shows ok/error/loading icons based on the field validity.
- // This feature requires Bootstrap v3.1.0 or later (http://getbootstrap.com/css/#forms-control-validation).
- // Since Bootstrap doesn't provide any methods to know its version, this option cannot be on/off automatically.
- // In other word, to use this feature you have to upgrade your Bootstrap to v3.1.0 or later.
- //
- // Examples:
- // - Use Glyphicons icons:
- // feedbackIcons: {
- // valid: 'glyphicon glyphicon-ok',
- // invalid: 'glyphicon glyphicon-remove',
- // validating: 'glyphicon glyphicon-refresh'
- // }
- // - Use FontAwesome icons:
- // feedbackIcons: {
- // valid: 'fa fa-check',
- // invalid: 'fa fa-times',
- // validating: 'fa fa-refresh'
- // }
- feedbackIcons: {
- valid: null,
- invalid: null,
- validating: null
- },
- // The submit buttons selector
- // These buttons will be disabled to prevent the valid form from multiple submissions
- submitButtons: 'button[type="submit"]',
- // The custom submit handler
- // It will prevent the form from the default submission
- //
- // submitHandler: function(validator, form) {
- // - validator is the BootstrapValidator instance
- // - form is the jQuery object present the current form
- // }
- submitHandler: null,
- // Live validating option
- // Can be one of 3 values:
- // - enabled: The plugin validates fields as soon as they are changed
- // - disabled: Disable the live validating. The error messages are only shown after the form is submitted
- // - submitted: The live validating is enabled after the form is submitted
- live: 'enabled',
- // Map the field name with validator rules
- fields: null
- };
- BootstrapValidator.prototype = {
- constructor: BootstrapValidator,
- /**
- * Init form
- */
- _init: function() {
- if (this.options.fields == null) {
- return;
- }
- var that = this;
- this.$form
- // Disable client side validation in HTML 5
- .attr('novalidate', 'novalidate')
- .addClass(this.options.elementClass)
- // Disable the default submission first
- .on('submit.bootstrapValidator', function(e) {
- e.preventDefault();
- that.validate();
- })
- .find(this.options.submitButtons)
- .on('click', function() {
- that.$submitButton = $(this);
- });
- for (var field in this.options.fields) {
- this._initField(field);
- }
- this._setLiveValidating();
- },
- /**
- * Init field
- *
- * @param {String} field The field name
- */
- _initField: function(field) {
- if (this.options.fields[field] == null || this.options.fields[field].validators == null) {
- return;
- }
- this.dfds[field] = {};
- this.results[field] = {};
- var fields = this.getFieldElements(field);
- // We don't need to validate non-existing fields
- if (fields == null) {
- delete this.options.fields[field];
- delete this.dfds[field];
- return;
- }
- fields.attr('data-bv-field', field);
- // Create help block elements for showing the error messages
- var $field = $(fields[0]),
- $parent = $field.parents('.form-group'),
- // Allow user to indicate where the error messages are shown
- $message = this.options.fields[field].container ? $parent.find(this.options.fields[field].container) : this._getMessageContainer($field);
- $field.data('bootstrapValidator.messageContainer', $message);
- for (var validatorName in this.options.fields[field].validators) {
- if (!$.fn.bootstrapValidator.validators[validatorName]) {
- delete this.options.fields[field].validators[validatorName];
- continue;
- }
- this.results[field][validatorName] = this.STATUS_NOT_VALIDATED;
- $('<small/>')
- .css('display', 'none')
- .attr('data-bv-validator', validatorName)
- .html(this.options.fields[field].validators[validatorName].message || this.options.message)
- .addClass('help-block')
- .appendTo($message);
- }
- // Prepare the feedback icons
- // Available from Bootstrap 3.1 (http://getbootstrap.com/css/#forms-control-validation)
- if (this.options.feedbackIcons
- && this.options.feedbackIcons.validating && this.options.feedbackIcons.invalid && this.options.feedbackIcons.valid)
- {
- $parent.addClass('has-feedback');
- var $icon = $('<i/>').css('display', 'none').addClass('form-control-feedback').attr('data-bv-field', field).insertAfter($(fields[fields.length - 1]));
- // The feedback icon does not render correctly if there is no label
- // https://github.com/twbs/bootstrap/issues/12873
- if ($parent.find('label').length == 0) {
- $icon.css('top', 0);
- }
- }
- if (this.options.fields[field]['enabled'] == null) {
- this.options.fields[field]['enabled'] = true;
- }
- // Whenever the user change the field value, mark it as not validated yet
- var that = this,
- type = fields.attr('type'),
- event = ('radio' == type || 'checkbox' == type || 'SELECT' == fields[0].tagName) ? 'change' : 'keyup';
- fields.on(event + '.bootstrapValidator', function() {
- that.updateStatus($field, that.STATUS_NOT_VALIDATED, null);
- });
- },
- /**
- * Get the element to place the error messages
- *
- * @param {jQuery} $field The field element
- * @returns {jQuery}
- */
- _getMessageContainer: function($field) {
- var $parent = $field.parent();
- if ($parent.hasClass('form-group')) {
- return $parent;
- }
- var cssClasses = $parent.attr('class');
- if (!cssClasses) {
- return this._getMessageContainer($parent);
- }
- cssClasses = cssClasses.split(' ');
- var n = cssClasses.length;
- for (var i = 0; i < n; i++) {
- if (/^col-(xs|sm|md|lg)-\d+$/.test(cssClasses[i]) || /^col-(xs|sm|md|lg)-offset-\d+$/.test(cssClasses[i])) {
- return $parent;
- }
- }
- return this._getMessageContainer($parent);
- },
- /**
- * Enable live validating
- */
- _setLiveValidating: function() {
- if ('enabled' == this.options.live) {
- var that = this;
- for (var field in this.options.fields) {
- (function(f) {
- var fields = that.getFieldElements(f);
- if (fields) {
- var type = fields.attr('type'),
- event = ('radio' == type || 'checkbox' == type || 'SELECT' == fields[0].tagName) ? 'change' : 'keyup';
- fields.on(event + '.bootstrapValidator', function() {
- that.validateField(f);
- });
- }
- })(field);
- }
- }
- },
- /**
- * Disable/Enable submit buttons
- *
- * @param {Boolean} disabled
- */
- _disableSubmitButtons: function(disabled) {
- if (!disabled) {
- this.$form.find(this.options.submitButtons).removeAttr('disabled');
- } else if (this.options.live != 'disabled') {
- // Don't disable if the live validating mode is disabled
- this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
- }
- },
- /**
- * Called when all validations are completed
- */
- _submit: function() {
- if (!this.isValid()) {
- if ('submitted' == this.options.live) {
- this.options.live = 'enabled';
- this._setLiveValidating();
- }
- // Focus to the first invalid field
- if (this.invalidField) {
- this.getFieldElements(this.invalidField).focus();
- }
- return;
- }
- this._disableSubmitButtons(true);
- // Call the custom submission if enabled
- if (this.options.submitHandler && 'function' == typeof this.options.submitHandler) {
- this.options.submitHandler.call(this, this, this.$form, this.$submitButton);
- } else {
- // Submit form
- this.$form.off('submit.bootstrapValidator').submit();
- }
- },
- // --- Public methods ---
- /**
- * Retrieve the field elements by given name
- *
- * @param {String} field The field name
- * @returns {null|jQuery[]}
- */
- getFieldElements: function(field) {
- var fields = this.$form.find(this.options.fields[field].selector || '[name="' + field + '"]');
- return (fields.length == 0) ? null : fields;
- },
- /**
- * Validate the form
- *
- * @return {BootstrapValidator}
- */
- validate: function() {
- if (!this.options.fields) {
- return this;
- }
- this._disableSubmitButtons(true);
- for (var field in this.options.fields) {
- this.validateField(field);
- }
- this._submit();
- return this;
- },
- /**
- * Validate given field
- *
- * @param {String} field The field name
- */
- validateField: function(field) {
- if (!this.options.fields[field]['enabled']) {
- return;
- }
- var that = this,
- fields = this.getFieldElements(field),
- $field = $(fields[0]),
- validators = this.options.fields[field].validators,
- validatorName,
- validateResult;
- // We don't need to validate disabled field
- if (fields.length == 1 && fields.is(':disabled')) {
- delete this.options.fields[field];
- delete this.dfds[field];
- return;
- }
- for (validatorName in validators) {
- if (this.dfds[field][validatorName]) {
- this.dfds[field][validatorName].reject();
- }
- // Don't validate field if it is already done
- if (this.results[field][validatorName] == this.STATUS_VALID || this.results[field][validatorName] == this.STATUS_INVALID) {
- continue;
- }
- this.results[field][validatorName] = this.STATUS_VALIDATING;
- validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
- if ('object' == typeof validateResult) {
- this.updateStatus($field, this.STATUS_VALIDATING, validatorName);
- this.dfds[field][validatorName] = validateResult;
- validateResult.done(function(isValid, v) {
- // v is validator name
- delete that.dfds[field][v];
- that.updateStatus($field, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
- if (isValid && 'disabled' == that.options.live) {
- that._submit();
- }
- });
- } else if ('boolean' == typeof validateResult) {
- this.updateStatus($field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
- }
- }
- },
- /**
- * Check the form validity
- *
- * @returns {Boolean}
- */
- isValid: function() {
- var field, validatorName;
- for (field in this.results) {
- if (!this.options.fields[field]['enabled']) {
- continue;
- }
- for (validatorName in this.results[field]) {
- if (this.results[field][validatorName] == this.STATUS_NOT_VALIDATED || this.results[field][validatorName] == this.STATUS_VALIDATING) {
- return false;
- }
- if (this.results[field][validatorName] == this.STATUS_INVALID) {
- this.invalidField = field;
- return false;
- }
- }
- }
- return true;
- },
- /**
- * Update field status
- *
- * @param {String|jQuery} field The field name or field element
- * @param {String} status The status
- * Can be 'NOT_VALIDATED', 'VALIDATING', 'INVALID' or 'VALID'
- * @param {String|null} validatorName The validator name. If null, the method updates validity result for all validators
- * @return {BootstrapValidator}
- */
- updateStatus: function(field, status, validatorName) {
- var $field = ('string' == typeof field) ? this.getFieldElements(field) : field,
- that = this,
- field = $field.attr('data-bv-field'),
- $parent = $field.parents('.form-group'),
- $message = $field.data('bootstrapValidator.messageContainer'),
- $errors = $message.find('.help-block[data-bv-validator]'),
- $icon = $parent.find('.form-control-feedback[data-bv-field="' + field + '"]');
- // Update status
- if (validatorName) {
- this.results[field][validatorName] = status;
- } else {
- for (var v in this.options.fields[field].validators) {
- this.results[field][v] = status;
- }
- }
- // Show/hide error elements and feedback icons
- switch (status) {
- case this.STATUS_VALIDATING:
- this._disableSubmitButtons(true);
- $parent.removeClass('has-success').removeClass('has-error');
- // TODO: Show validating message
- validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
- if ($icon) {
- $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).addClass(this.options.feedbackIcons.validating).show();
- }
- break;
- case this.STATUS_INVALID:
- this._disableSubmitButtons(true);
- $parent.removeClass('has-success').addClass('has-error');
- validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').show() : $errors.show();
- if ($icon) {
- $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.validating).addClass(this.options.feedbackIcons.invalid).show();
- }
- break;
- case this.STATUS_VALID:
- validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
- // If the field is valid
- if ($errors.filter(function() {
- var display = $(this).css('display'), v = $(this).attr('data-bv-validator');
- return ('block' == display) || (that.results[field][v] != that.STATUS_VALID);
- }).length == 0
- ) {
- this._disableSubmitButtons(false);
- $parent.removeClass('has-error').addClass('has-success');
- if ($icon) {
- $icon.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(false);
- $parent.removeClass('has-success').removeClass('has-error');
- validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
- if ($icon) {
- $icon.removeClass(this.options.feedbackIcons.valid).removeClass(this.options.feedbackIcons.invalid).removeClass(this.options.feedbackIcons.validating).hide();
- }
- break;
- }
- return this;
- },
- // Useful APIs which aren't used internally
- /**
- * Reset the form
- *
- * @param {Boolean} resetFormData Reset current form data
- * @return {BootstrapValidator}
- */
- resetForm: function(resetFormData) {
- var field, $field, type;
- for (field in this.options.fields) {
- this.dfds[field] = {};
- this.results[field] = {};
- $field = this.getFieldElements(field);
- // Mark field as not validated yet
- this.updateStatus($field, this.STATUS_NOT_VALIDATED, null);
- if (resetFormData) {
- type = $field.attr('type');
- ('radio' == type || 'checkbox' == type) ? $field.removeAttr('checked').removeAttr('selected') : $field.val('');
- }
- }
- this.invalidField = null;
- this.$submitButton = null;
- // Enable submit buttons
- this._disableSubmitButtons(false);
- return this;
- },
- /**
- * Enable/Disable all validators to given field
- *
- * @param {String} field The field name
- * @param {Boolean} enabled Enable/Disable field validators
- * @return {BootstrapValidator}
- */
- enableFieldValidators: function(field, enabled) {
- this.options.fields[field]['enabled'] = enabled;
- this.updateStatus(field, this.STATUS_NOT_VALIDATED, null);
- return this;
- }
- };
- // Plugin definition
- $.fn.bootstrapValidator = function(options) {
- return this.each(function() {
- var $this = $(this), data = $this.data('bootstrapValidator');
- if (!data) {
- $this.data('bootstrapValidator', (data = new BootstrapValidator(this, options)));
- }
- if ('string' == typeof options) {
- data[options]();
- }
- });
- };
- // Available validators
- $.fn.bootstrapValidator.validators = {};
- $.fn.bootstrapValidator.Constructor = BootstrapValidator;
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.base64 = {
- /**
- * Return true if the input value is a base 64 encoded string.
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.between = {
- /**
- * Return true if the input value is between (strictly or not) two given numbers
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - min
- * - max
- * - inclusive [optional]: Can be true or false. Default is true
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- value = parseFloat(value);
- return (options.inclusive === true)
- ? (value > options.min && value < options.max)
- : (value >= options.min && value <= options.max);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.callback = {
- /**
- * Return result from the callback method
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - callback: The callback method that passes 2 parameters:
- * callback: function(fieldValue, validator) {
- * // fieldValue is the value of field
- * // validator is instance of BootstrapValidator
- * }
- * - message: The invalid message
- * @returns {Boolean|Deferred}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (options.callback && 'function' == typeof options.callback) {
- var dfd = new $.Deferred();
- dfd.resolve(options.callback.call(this, value, validator), 'callback');
- return dfd;
- }
- return true;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.choice = {
- /**
- * Check if the number of checked boxes are less or more than a given number
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consists of following keys:
- * - min
- * - max
- * At least one of two keys is required
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var numChoices = validator
- .getFieldElements($field.attr('data-bv-field'))
- .filter(':checked')
- .length;
- if ((options.min && numChoices < options.min) || (options.max && numChoices > options.max)) {
- return false;
- }
- return true;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.creditCard = {
- /**
- * Return true if the input value is valid credit card number
- * Based on https://gist.github.com/DiegoSalazar/4075533
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following key:
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- // Accept only digits, dashes or spaces
- if (/[^0-9-\s]+/.test(value)) {
- return false;
- }
- value = value.replace(/\D/g, '');
- // Validate the check sum
- // The Luhn Algorithm
- // http://en.wikipedia.org/wiki/Luhn
- var check = 0, digit = 0, even = false, length = value.length;
- for (var n = length - 1; n >= 0; n--) {
- digit = parseInt(value.charAt(n), 10);
- if (even) {
- if ((digit *= 2) > 9) {
- digit -= 9;
- }
- }
- check += digit;
- even = !even;
- }
- if ((check % 10) != 0) {
- return false;
- }
- // Validate the card number based on prefix (IIN ranges) and length
- var cards = {
- AMERICAN_EXPRESS: {
- length: [15],
- prefix: ['34', '37']
- },
- DINERS_CLUB: {
- length: [14],
- prefix: ['300', '301', '302', '303', '304', '305', '36']
- },
- DINERS_CLUB_US: {
- length: [16],
- prefix: ['54', '55']
- },
- DISCOVER: {
- length: [16],
- prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
- '62214', '62215', '62216', '62217', '62218', '62219',
- '6222', '6223', '6224', '6225', '6226', '6227', '6228',
- '62290', '62291', '622920', '622921', '622922', '622923',
- '622924', '622925', '644', '645', '646', '647', '648',
- '649', '65']
- },
- JCB: {
- length: [16],
- prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
- },
- LASER: {
- length: [16, 17, 18, 19],
- prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
- },
- MAESTRO: {
- length: [12, 13, 14, 15, 16, 17, 18, 19],
- prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
- },
- MASTERCARD: {
- length: [16],
- prefix: ['51', '52', '53', '54', '55']
- },
- SOLO: {
- length: [16, 18, 19],
- prefix: ['6334', '6767']
- },
- UNIONPAY: {
- length: [16, 17, 18, 19],
- prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
- '62215', '62216', '62217', '62218', '62219', '6222', '6223',
- '6224', '6225', '6226', '6227', '6228', '62290', '62291',
- '622920', '622921', '622922', '622923', '622924', '622925']
- },
- VISA: {
- length: [16],
- prefix: ['4']
- }
- };
- var type, i;
- for (type in cards) {
- for (i in cards[type]['prefix']) {
- if (value.substr(0, cards[type]['prefix'][i].length) == cards[type]['prefix'][i] // Check the prefix
- && cards[type]['length'].indexOf(value.length) != -1) // and length
- {
- return true;
- }
- }
- }
- return false;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.cvv = {
- /**
- * Return true if the input value is a valid CVV number.
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - creditCardField: The credit card number field. It can be null
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- if (!/^[0-9]{3,4}$/.test(value)) {
- return false;
- }
- if (!options.creditCardField) {
- return true;
- }
- // Get the credit card number
- var creditCard = validator.getFieldElements(options.creditCardField).val();
- if (creditCard == '') {
- return true;
- }
- // Supported credit card types
- var cards = {
- AMERICAN_EXPRESS: {
- length: [15],
- prefix: ['34', '37']
- },
- DINERS_CLUB: {
- length: [14],
- prefix: ['300', '301', '302', '303', '304', '305', '36']
- },
- DINERS_CLUB_US: {
- length: [16],
- prefix: ['54', '55']
- },
- DISCOVER: {
- length: [16],
- prefix: ['6011', '622126', '622127', '622128', '622129', '62213',
- '62214', '62215', '62216', '62217', '62218', '62219',
- '6222', '6223', '6224', '6225', '6226', '6227', '6228',
- '62290', '62291', '622920', '622921', '622922', '622923',
- '622924', '622925', '644', '645', '646', '647', '648',
- '649', '65']
- },
- JCB: {
- length: [16],
- prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
- },
- LASER: {
- length: [16, 17, 18, 19],
- prefix: ['3528', '3529', '353', '354', '355', '356', '357', '358']
- },
- MAESTRO: {
- length: [12, 13, 14, 15, 16, 17, 18, 19],
- prefix: ['5018', '5020', '5038', '6304', '6759', '6761', '6762', '6763', '6764', '6765', '6766']
- },
- MASTERCARD: {
- length: [16],
- prefix: ['51', '52', '53', '54', '55']
- },
- SOLO: {
- length: [16, 18, 19],
- prefix: ['6334', '6767']
- },
- UNIONPAY: {
- length: [16, 17, 18, 19],
- prefix: ['622126', '622127', '622128', '622129', '62213', '62214',
- '62215', '62216', '62217', '62218', '62219', '6222', '6223',
- '6224', '6225', '6226', '6227', '6228', '62290', '62291',
- '622920', '622921', '622922', '622923', '622924', '622925']
- },
- VISA: {
- length: [16],
- prefix: ['4']
- }
- };
- var type, i, creditCardType = null;
- for (type in cards) {
- for (i in cards[type]['prefix']) {
- if (creditCard.substr(0, cards[type]['prefix'][i].length) == cards[type]['prefix'][i] // Check the prefix
- && cards[type]['length'].indexOf(creditCard.length) != -1) // and length
- {
- creditCardType = type;
- break;
- }
- }
- }
- return (creditCardType == null)
- ? false
- : (('AMERICAN_EXPRESS' == creditCardType) ? (value.length == 4) : (value.length == 3));
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.date = {
- /**
- * Return true if the input value is valid date
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - format: The date format. Default is MM/DD/YYYY
- * Support the following formats:
- * YYYY/DD/MM
- * YYYY/DD/MM h:m A
- * YYYY/MM/DD
- * YYYY/MM/DD h:m A
- *
- * YYYY-DD-MM
- * YYYY-DD-MM h:m A
- * YYYY-MM-DD
- * YYYY-MM-DD h:m A
- *
- * MM/DD/YYYY
- * MM/DD/YYYY h:m A
- * DD/MM/YYYY
- * DD/MM/YYYY h:m A
- *
- * MM-DD-YYYY
- * MM-DD-YYYY h:m A
- * DD-MM-YYYY
- * DD-MM-YYYY h:m A
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- // Determine the separator
- options.format = options.format || 'MM/DD/YYYY';
- var separator = (options.format.indexOf('/') != -1)
- ? '/'
- : ((options.format.indexOf('-') != -1) ? '-' : null);
- if (separator == null) {
- return false;
- }
- var month, day, year, minutes = null, hours = null, matches;
- switch (true) {
- case (separator == '/' && (matches = value.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/i)) && options.format == 'YYYY/DD/MM'):
- case (separator == '-' && (matches = value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/i)) && options.format == 'YYYY-DD-MM'):
- year = matches[1]; day = matches[2]; month = matches[3];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/i)) && options.format == 'DD/MM/YYYY'):
- case (separator == '-' && (matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/i)) && options.format == 'DD-MM-YYYY'):
- day = matches[1]; month = matches[2]; year = matches[3];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/i)) && options.format == 'YYYY/MM/DD'):
- case (separator == '-' && (matches = value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/i)) && options.format == 'YYYY-MM-DD'):
- year = matches[1]; month = matches[2]; day = matches[3];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/i)) && options.format == 'MM/DD/YYYY'):
- case (separator == '-' && (matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})$/i)) && options.format == 'MM-DD-YYYY'):
- month = matches[1]; day = matches[2]; year = matches[3];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'YYYY/DD/MM h:m A'):
- case (separator == '-' && (matches = value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'YYYY-DD-MM h:m A'):
- year = matches[1]; day = matches[2]; month = matches[3]; hours = matches[4]; minutes = matches[5];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'DD/MM/YYYY h:m A'):
- case (separator == '-' && (matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'DD-MM-YYYY h:m A'):
- day = matches[1]; month = matches[2]; year = matches[3]; hours = matches[4]; minutes = matches[5];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'YYYY/MM/DD h:m A'):
- case (separator == '-' && (matches = value.match(/^(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'YYYY-MM-DD h:m A'):
- year = matches[1]; month = matches[2]; day = matches[3]; hours = matches[4]; minutes = matches[5];
- break;
- case (separator == '/' && (matches = value.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'MM/DD/YYYY h:m A'):
- case (separator == '-' && (matches = value.match(/^(\d{1,2})-(\d{1,2})-(\d{4})\s+(\d{1,2}):(\d{1,2})\s+(AM|PM)$/i)) && options.format == 'MM-DD-YYYY h:m A'):
- month = matches[1]; day = matches[2]; year = matches[3]; hours = matches[4]; minutes = matches[5];
- break;
- default:
- return false;
- }
- // Validate hours and minutes
- if (hours && minutes) {
- hours = parseInt(hours, 10);
- minutes = parseInt(minutes, 10);
- if (hours < 1 || hours > 12 || minutes < 0 || minutes > 59) {
- return false;
- }
- }
- // Validate day, month, and year
- day = parseInt(day, 10);
- month = parseInt(month, 10);
- year = parseInt(year, 10);
- if (year < 1000 || year > 9999 || month == 0 || month > 12) {
- return false;
- }
- var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- // Update the number of days in Feb of leap year
- if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
- numDays[1] = 29;
- }
- // Check the day
- return (day > 0 && day <= numDays[month - 1]);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.different = {
- /**
- * Return true if the input value is different with given field's value
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consists of the following key:
- * - field: The name of field that will be used to compare with current one
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- var compareWith = validator.getFieldElements(options.field);
- if (compareWith == null) {
- return true;
- }
- if (value != compareWith.val()) {
- validator.updateStatus(compareWith, validator.STATUS_VALID, 'different');
- return true;
- } else {
- return false;
- }
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.digits = {
- /**
- * Return true if the input value contains digits only
- *
- * @param {BootstrapValidator} validator Validate plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- return /^\d+$/.test(value);
- }
- }
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.emailAddress = {
- /**
- * Return true if and only if the input value is a valid email address
- *
- * @param {BootstrapValidator} validator Validate plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- // Email address regular expression
- // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
- var emailRegExp = /^(([^<>()[\]\\.,;:\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 emailRegExp.test(value);
- }
- }
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.greaterThan = {
- /**
- * Return true if the input value is greater than or equals to given number
- *
- * @param {BootstrapValidator} validator Validate plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - value: The number used to compare to
- * - inclusive [optional]: Can be true or false. Default is true
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- value = parseFloat(value);
- return (options.inclusive === true) ? (value > options.value) : (value >= options.value);
- }
- }
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.hexColor = {
- /**
- * Return true if the input value is a valid hex color
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.identical = {
- /**
- * Check if input value equals to value of particular one
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consists of the following key:
- * - field: The name of field that will be used to compare with current one
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- var compareWith = validator.getFieldElements(options.field);
- if (compareWith == null) {
- return true;
- }
- if (value == compareWith.val()) {
- validator.updateStatus(compareWith, validator.STATUS_VALID, 'identical');
- return true;
- } else {
- return false;
- }
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.ip = {
- /**
- * Return true if the input value is a IP address.
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - ipv4: Enable IPv4 validator, default to true
- * - ipv6: Enable IPv6 validator, default to true
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- options = $.extend({}, { ipv4: true, ipv6: true }, options);
- if (options.ipv4) {
- return /^(?:(?: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]?)$/.test(value);
- } else if (options.ipv6) {
- return /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/.test(str);
- }
- return false;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.isbn = {
- /**
- * Return true if the input value is a valid ISBN 10 or ISBN 13 number
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- // Replace all special characters except digits and X
- value = value.replace(/[^\dX]/gi, '');
- var chars = value.split(''),
- sum = 0,
- checksum;
- // See http://en.wikipedia.org/wiki/International_Standard_Book_Number
- switch (chars.length) {
- // ISBN 10
- case 10:
- sum = 0;
- for (var i = 0; i < 9; i++) {
- sum += ((10 - i) * parseInt(chars[i]));
- }
- checksum = 11 - (sum % 11);
- if (checksum == 11) {
- checksum = 0;
- } else if (checksum == 10) {
- checksum = 'X';
- }
- return (checksum == chars[9]);
- // ISBN 13
- case 13:
- sum = 0;
- for (var i = 0; i < 12; i++) {
- sum += ((i % 2 == 0) ? parseInt(chars[i]) : (parseInt(chars[i]) * 3));
- }
- checksum = 10 - (sum % 10);
- if (checksum == 10) {
- checksum = '0';
- }
- return (checksum == chars[12]);
- default:
- return false;
- }
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.lessThan = {
- /**
- * Return true if the input value is less than or equal to given number
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - value: The number used to compare to
- * - inclusive [optional]: Can be true or false. Default is true
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- value = parseFloat(value);
- return (options.inclusive === true) ? (value < options.value) : (value <= options.value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.mac = {
- /**
- * Return true if the input value is a MAC address.
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.notEmpty = {
- /**
- * Check if input value is empty or not
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var type = $field.attr('type');
- if ('radio' == type || 'checkbox' == type) {
- return validator
- .getFieldElements($field.attr('data-bv-field'))
- .filter(':checked')
- .length > 0;
- }
- return $.trim($field.val()) != '';
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.phone = {
- /**
- * Return true if the input value contains a valid US phone number only
- *
- * @param {BootstrapValidator} validator Validate plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consist of key:
- * - country: The ISO 3166 country code
- *
- * Currently it only supports United State (US) country
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- options.country = options.country || 'US';
- switch (options.country.toUpperCase()) {
- case 'US':
- default:
- value = value.replace(/\(|\)|\s+/g, '');
- return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
- }
- }
- }
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.regexp = {
- /**
- * Check if the element value matches given regular expression
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consists of the following key:
- * - regexp: The regular expression you need to check
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- return options.regexp.test(value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.remote = {
- /**
- * Request a remote server to check the input value
- *
- * @param {BootstrapValidator} validator Plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - url
- * - data [optional]: By default, it will take the value
- * {
- * <fieldName>: <fieldValue>
- * }
- * - message: The invalid message
- * @returns {Boolean|Deferred}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- var name = $field.attr('data-bv-field'), data = options.data;
- if (data == null) {
- data = {};
- }
- // Support dynamic data
- if ('function' == typeof data) {
- data = data.call(this, validator);
- }
- data[name] = value;
- var dfd = new $.Deferred();
- var xhr = $.ajax({
- type: 'POST',
- url: options.url,
- dataType: 'json',
- data: data
- });
- xhr.then(function(response) {
- dfd.resolve(response.valid === true || response.valid === 'true', 'remote');
- });
- dfd.fail(function() {
- xhr.abort();
- });
- return dfd;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.step = {
- /**
- * Return true if the input value is valid step one
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Can consist of the following keys:
- * - baseValue: The base value
- * - step: The step
- * - message: The invalid message
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- options = $.extend({}, { baseValue: 0, step: 1 }, options);
- value = parseFloat(value);
- if (isNaN(value) || !isFinite(value)) {
- return false;
- }
- var round = function(x, precision) {
- var m = Math.pow(10, precision);
- x = x * m;
- var sign = (x > 0) | -(x < 0),
- isHalf = (x % 1 === 0.5 * sign);
- if (isHalf) {
- return (Math.floor(x) + (sign > 0)) / m;
- } else {
- return Math.round(x) / m;
- }
- },
- floatMod = function(x, y) {
- if (y == 0.0) {
- return 1.0;
- }
- var dotX = (x + '').split('.'),
- dotY = (y + '').split('.'),
- precision = ((dotX.length == 1) ? 0 : dotX[1].length) + ((dotY.length == 1) ? 0 : dotY[1].length);
- return round(x - y * Math.floor(x / y), precision);
- };
- var mod = floatMod(value - options.baseValue, options.step);
- return (mod == 0.0 || mod == options.step);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.stringLength = {
- /**
- * Check if the length of element value is less or more than given number
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consists of following keys:
- * - min
- * - max
- * At least one of two keys is required
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- var length = $.trim(value).length;
- if ((options.min && length < options.min) || (options.max && length > options.max)) {
- return false;
- }
- return true;
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.uri = {
- /**
- * Return true if the input value is a valid URL
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '') {
- return true;
- }
- // Credit to https://gist.github.com/dperini/729294
- //
- // Regular Expression for URL validation
- //
- // Author: Diego Perini
- // Updated: 2010/12/05
- //
- // the regular expression composed & commented
- // could be easily tweaked for RFC compliance,
- // it was expressly modified to fit & satisfy
- // these test for an URL shortener:
- //
- // http://mathiasbynens.be/demo/url-regex
- //
- // Notes on possible differences from a standard/generic validation:
- //
- // - utf-8 char class take in consideration the full Unicode range
- // - TLDs have been made mandatory so single names like "localhost" fails
- // - protocols have been restricted to ftp, http and https only as requested
- //
- // Changes:
- //
- // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
- // first and last IP address of each class is considered invalid
- // (since they are broadcast/network addresses)
- //
- // - Added exclusion of private, reserved and/or local networks ranges
- //
- // Compressed one-line versions:
- //
- // Javascript version
- //
- // /^(?:(?: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
- //
- // PHP version
- //
- // _^(?:(?: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\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS
- var urlExp = new RegExp(
- "^" +
- // protocol identifier
- "(?:(?:https?|ftp)://)" +
- // user:pass authentication
- "(?:\\S+(?::\\S*)?@)?" +
- "(?:" +
- // IP address exclusion
- // private & local networks
- "(?!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})" +
- // IP address dotted notation octets
- // excludes loopback network 0.0.0.0
- // excludes reserved space >= 224.0.0.0
- // excludes network & broacast addresses
- // (first & last IP address of each class)
- "(?:[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]))" +
- "|" +
- // host name
- "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
- // domain name
- "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
- // TLD identifier
- "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
- ")" +
- // port number
- "(?::\\d{2,5})?" +
- // resource path
- "(?:/[^\\s]*)?" +
- "$", "i"
- );
- return urlExp.test(value);
- }
- };
- }(window.jQuery));
- ;(function($) {
- $.fn.bootstrapValidator.validators.zipCode = {
- /**
- * Return true if and only if the input value is a valid country zip code
- *
- * @param {BootstrapValidator} validator The validator plugin instance
- * @param {jQuery} $field Field element
- * @param {Object} options Consist of key:
- * - country: The ISO 3166 country code
- *
- * Currently it supports the following countries:
- * - US (United State)
- * - DK (Denmark)
- * - SE (Sweden)
- *
- * @returns {Boolean}
- */
- validate: function(validator, $field, options) {
- var value = $field.val();
- if (value == '' || !options.country) {
- return true;
- }
- options.country = options.country || 'US';
- switch (options.country.toUpperCase()) {
- case 'DK':
- return /^(DK(-|\s)?)?\d{4}$/i.test(value);
- case 'SE':
- return /^(S-)?\d{3}\s?\d{2}$/i.test(value);
- case 'US':
- default:
- return /^\d{5}([\-]\d{4})?$/.test(value);
- }
- }
- };
- }(window.jQuery));
|