Code: Select all
String.prototype.trim = function()
{
return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
//Example usage
var someString = ' foo '; //Whitespace galore
var newString = someString.trim();
alert(newString);