Search
Categories
Calendar
December 2009
M T W T F S S
« Nov    
 123456
78910111213
14151617181920
21222324252627
28293031  

Regular Expression based Javascript Trim

There are several ways to trim a string in Javascript. Here are some examples of Trim Function by Regular Expression.

Trim Left

function trimLeft(str)
{
return str.replace(/^\s+/g, "");
}

Trim Right

function trimRight(str)
{
return str.replace(/\s+$/g, "");
}

Trim Both

function jsTrim(str)
{
return str.replace(/^\s+|\s+$/g, "");
}

Trim

Leave a Reply