tags:

views:

790

answers:

2

How to do Trim operation to remove space character in a text field in JavaScript?

+2  A: 

A total dupe of this question:

http://stackoverflow.com/questions/196925/what-is-the-best-way-to-trim-in-javascript

Unless you didn't actually mean trim of course and in fact wanted all the spaces replaced ? In which case you just want:

var myString = "foo bar ddd";
myString = myString.replace(/ /g, "");
andynormancx
+2  A: 

in case you did mean Trim:

x.replace(/^\s*|\s*$/g,'');

annakata