I have strings with extra whitespaces, each time there's more than only one whitespace I'd like it be only one.
Anyone? I tried searching google, but nothing worked for me.
Thanks
I have strings with extra whitespaces, each time there's more than only one whitespace I'd like it be only one.
Anyone? I tried searching google, but nothing worked for me.
Thanks
using a regular expression with the replace function does the trick:
Here's a non-regex solution (just for fun):
It splits the string by it's whitespaces, remove them all from the array, and joins all the words again, with a single whitespace in between them.
If you want to restrict user to give blank space in the name just create a if statement and give the condition. like I did:
jQuery.trim() works well.
http://api.jquery.com/jQuery.trim/
var x = " Test Test Test ".split(" ").join(""); alert(x);