Skip to content

Instantly share code, notes, and snippets.

@eralston
Created May 13, 2011 16:31
Show Gist options
  • Save eralston/970842 to your computer and use it in GitHub Desktop.
Save eralston/970842 to your computer and use it in GitHub Desktop.
JavaScript snippet for trimming whitespace from strings - http://www.somacon.com/p355.php
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+$/,"");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment