//Function to trim the space in the left side of the string
function ltrim ( s ){
  return s.replace( /^\s*/, "" );
}

//Function to trim the space in the right side of the string
function rtrim ( s ){
   return s.replace( /\s*$/, "" );
}

//*Function to trim the space in the  string
function trim(s) {
   var temp = s;
   return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}



 
ltrim() will remove all the spaces to the left in a string rtrim() will remove all the spaces to the right in a string trim() will all the left , right and spaces inside the string Ex: var x = " thestring"; ltrim(x) will return "thestring"; var y = "thestring "; rtrim(y) will return "thestring"; var z = " the st ri ng "; trim(z) will return "thestring"