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

Snippets has posted 5883 posts at DZone. View Full User Profile

Javascript String Trimming Prototypes

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

String.prototype.ltrim = function() {
 return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
 return this.replace(/\s+$/,"");
}