102
rated 0 times
[
103]
[
1]
/ answers: 1 / hits: 32312
/ 9 Years ago, thu, november 12, 2015, 12:00:00
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 onchange event
<javascript>
function trim(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;
}
</script>
<p>Search1: <input type="text" onchange="return trim(this)" /></p>
<p>Search2: <input type="text" onchange="return trim(this)" /></p>
<p>Search3: <input type="text" onchange="return trim(this)" /></p>
<p>Search4: <input type="text" onchange="return trim(this)" /></p>
<p>Search5: <input type="text" onchange="return trim(this)" /></p>
Somebody can help me about how to make all my inputs trim input values (CSS OR JAVASCRIPT) like this:
<script>
Here in this script will trim blank spaces starting or ending so don't need to add anything in the input
</script>
<input type="text" />
I tried this but is not working
$(.input).text().trim()
Please somebody can help me?.
Thanks in advance.
More From » jquery