7.13.2009

javascript trim

//trim both side of space
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g, "");
}
//trim left side of space
function ltrim(str){
return str.replace(/(^\s*)/g,"");
}
//trim right side of space
function rtrim(str){
return str.replace(/(\s*$)/g,"");
}
function trimEnter(str){
return str.replace(/\n\r/gi,"");
}

No comments: