Trim function applied to Javascript

The following code will help to apply “Trim” function in javascript. Here is an example where we are retriving data from a prompt message box then applying “Ltrim” & “RTrim” like functions.

var sData = prompt(“Enter The Name”,”"); // Receives data from user
var sLeft = /\s*((\S+\s*)*)/;
var sRight = /((\s*\S+)*)\s*/;
sData = sData.replace(sLeft, “$1″); // Removes blank spaces from left
sData = sData.replace(sRight, “$1″); // Removes blank spaces from right

Tags:

Leave a Reply

Recent Comments

  • Stanford Reach: Great post. Thanks!
  • Shu Crunk: I was simply browsing for useful blog articles intended for a project research and I happened to stumble...
  • Marya: Hey rather wonderful weblog!! I’ll bookmark your weblog and grab the feeds conjointly…
  • John Vay: ive just started my own hosting company its such hard work haha :P
  • write a good resume: Your the best!