Looking for pure JavaScript works specially in IE to remove all extra white-spaces from all inputs (text and textarea).
Here is the jQuery version that works but I want it in JavaScript:
function TrimText(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;
}
What is best approach to convert this to JavaScript?
$j(function () {
$j("textarea").change(function () {
TrimText(this);
});
$j("input").change(function () {
TrimText(this);
});
});