I\'m trying to remove blank spaces from the begining and ending of inputs in general without adding a class or id or event
I tried this live demo but is using
This is one of the easiest way i found :), it uses jquery hope it helps, it uses your function The input have to be only:
This automatically change all inputs, or you can asign to a class
function trim_text(el) {
el.value = el.value.
replace(/(^\s*)|(\s*$)/gi, ""). // removes leading and trailing spaces
replace(/[ ]{2,}/gi, " "). // replaces multiple spaces with one space
replace(/\n +/, "\n"); // Removes spaces after newlines
return;
}
$(function(){
$("textarea").change(function() {
trim_text(this);
});
$("input").change(function() {
trim_text(this);
});
});