Skip to content Skip to sidebar Skip to footer

Javascript Regex- Remove All Spaces In String Except Between Words

I have a bit of a conundrum. I have a jquery modal dialog form that is bound to a click event of a table within an accordion. On click of a row, the dialog opens up with the inp

Solution 1:

Use .replace(/^\s+|\s+$/g,"") to trim spaces from the start and end of the string.


Solution 2:

jQuery has a built-in $.trim. In modern browsers there's String.prototype.trim:

$.trim(text); // jQuery

// OR

text.trim(); // modern browsers

Solution 3:

Try using .trim():

var trimmed = client.trim();

Post a Comment for "Javascript Regex- Remove All Spaces In String Except Between Words"