bootstrapvalidator
Version:
The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
41 lines (36 loc) • 1.36 kB
JavaScript
(function($) {
$.fn.bootstrapValidator.i18n.identical = $.extend($.fn.bootstrapValidator.i18n.identical || {}, {
'default': 'Please enter the same value'
});
$.fn.bootstrapValidator.validators.identical = {
html5Attributes: {
message: 'message',
field: 'field'
},
/**
* 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 || compareWith.length === 0) {
return true;
}
if (value === compareWith.val()) {
validator.updateStatus(options.field, validator.STATUS_VALID, 'identical');
return true;
} else {
return false;
}
}
};
}(window.jQuery));