DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Javascript Trim
Adds trim function to javascript string object.
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
Comments
Snippets Manager replied on Sun, 2010/04/25 - 11:06am
Snippets Manager replied on Fri, 2009/06/05 - 2:32am
Snippets Manager replied on Wed, 2008/06/25 - 6:05am
Snippets Manager replied on Wed, 2008/06/25 - 6:05am
Steven Levithan replied on Wed, 2008/01/30 - 12:58am
choonkeat chew replied on Fri, 2007/07/27 - 11:47pm
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
Snippets Manager replied on Wed, 2007/05/16 - 1:04pm
Snippets Manager replied on Wed, 2007/05/16 - 1:04pm
Snippets Manager replied on Thu, 2006/02/23 - 11:07am
// Removes leading whitespaces function LTrim( value ) { var re = /\s*((\S+\s*)*)/; return value.replace(re, "$1"); } // Removes ending whitespaces function RTrim( value ) { var re = /((\s*\S+)*)\s*/; return value.replace(re, "$1"); } // Removes leading and ending whitespaces function trim( value ) { return LTrim(RTrim(value)); }
Snippets Manager replied on Tue, 2005/12/13 - 12:20am