This function will strip out all tabs and return characters. It will also collapse all runs of multiple spaces down to one. It will also remove a leading and trailing spaces. It is similar to the php_strip_whiespace() function in PHP.
function collapseWhiteSpace( theString ) {
theString = theString.split("\r").join("");
theString = theString.split("\t").join("");
while ( theString.indexOf(" " ) != -1 ) {
theString= theString.split(" ").join(" ");
}
if (theString.substr(0,1) == " ") {
theString = theString.substr( 1 );
}
if (theString.substr( theString.length-1, 1 ) == " ") {
theString = theString.substr( 0, theString.length - 1 );
}
return( theString );
}