Easy code for Javascript trim function

by Preetha 2012-09-14 09:46:03

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
return stringToTrim.replace(/\s+$/,"");
}

Tagged in:

781
like
0
dislike
0
mail
flag

You must LOGIN to add comments