Skip to content

Instantly share code, notes, and snippets.

@phette23
Created April 8, 2012 18:04
Show Gist options
  • Save phette23/2338818 to your computer and use it in GitHub Desktop.
Save phette23/2338818 to your computer and use it in GitHub Desktop.
Crockford's String.trim() function
if (typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(
/^\s*(\S*(?:\s+\S+)*)\s*$/,
"$1");
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment