Monday, December 31, 2007

Trim Function in Javascript

Copy and Paste the following in code between <script> tags.

String.prototype.trim = function()
{
return( this.replace(new RegExp("^([\\s]+)([\\s]+)$", "gm"), ""));
};


We can use this function like,

var s = " Success Within You ";
alert(s.trim());


You will get "Success Within You"