JavaScript Trim Function

You have a Trim functionality on the server side, but what about at client side? Do we have some thing like Trim mechanism for client side scripts?
 
I guess, there is nothing like that... but I found a way to trim the given string.
 
// Replaces the trailing and leading spaces of a given string
function trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}
 
The above function returns the string after trimming. I'm posting this here, so that I can recollect as and when I want, instead of googling..
 
What do you say?
 

Comments

Popular posts from this blog

Network Intrusion Detection using Supervised ML technique

ASP.NET Page Life Cycle

Is Architecture = Design of the application