JavaScript Trim, LTrim, RTrim Functions using Regular Expressions
Tuesday, July 28, 2009
function jsTrim(stringToTrim) { return stringToTrim.replace(/^\s+\s+$/g,""); }
function jsLtrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); }
function jsRtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); }
Usage:
alert(jsTrim(" Webpage Tips "));
alert(jsLtrim(" Webpage Tips"));
alert(jsRtrim("Webpage Tips "));
0 comments:
Post a Comment