Skip to content

Instantly share code, notes, and snippets.

@Jerph
Last active December 18, 2015 15:39
Show Gist options
  • Save Jerph/5806096 to your computer and use it in GitHub Desktop.
Save Jerph/5806096 to your computer and use it in GitHub Desktop.
jQuery plugin to trim text inputs on change
/*!
* jquery.trimTextInputs.js v1.0.0
*
* Copyright 2013, Jeff Fendley
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
(function ($) {
// Trims text inputs on change
$.extend({
trimTextInputs: function (options) {
var exceptionsSelector = (options && options.exceptionsSelector) || '[data-no-trim]';
var selector = 'input:text:not(' + exceptionsSelector + '),textarea:not(' + exceptionsSelector + ')';
$('form').on('change', selector, function () {
$(this).val($.trim($(this).val()));
});
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment