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 - 12:06pm
Snippets Manager replied on Fri, 2009/06/05 - 3:32am
Snippets Manager replied on Wed, 2008/06/25 - 7:05am
Snippets Manager replied on Wed, 2008/06/25 - 7:05am
Steven Levithan replied on Wed, 2008/01/30 - 1:58am
choonkeat chew replied on Sat, 2007/07/28 - 12:47am
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };Snippets Manager replied on Wed, 2007/05/16 - 2:04pm
Snippets Manager replied on Wed, 2007/05/16 - 2:04pm
Snippets Manager replied on Thu, 2006/02/23 - 12:07pm
// 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 - 1:20am