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





