Skip to content
Advertisement

Tag: whitespace

Javascript to remove spaces from a textbox value

I’ve searched around for this a lot and can’t find a specific example of what I’m trying to do. Basically I want to get the value of a textbox, by the name of the text box (not id). Then I want to remove ALL spaces, not just leading or trailing, but spaces in the text too. For example for this

Check if a string has white space

I’m trying to check if a string has white space. I found this function but it doesn’t seem to be working: By the way, I added quotes to RegExp. Is there something wrong? Is there anything better that I can use? Hopefully JQuery. Answer You can simply use the indexOf method on the input string: Or you can use the

Advertisement