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

Marco has posted 3 posts at DZone. View Full User Profile

JavaScript Trim Prototype

03.13.2008
| 8482 views |
  • submit to reddit
        Trim function prototype:
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}

Example:
var mystring = " hello world ";
alert("[" + mystring.trim() + "]");