Tuesday, 27 September 2011

trim, ltrim, rtrim prototypes for JavaScript


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+$/,"");
}

No comments:

Post a Comment