Trim is a good features when you try to delete the space at the left most, right most or both the left most and right most of the string. The following trim function is ultilize the javascript Regular expression for the trim function
Left Trim
function ltrim(str){
return str.replace(/^s+/, ”);
}
Right Trim
function rtrim(str) {
return str.replace(/s+$/, ”);
}
All trim
function alltrim(str) {
return str.replace(/^s+|s+$/g, ”);
}