rtrim, ltrim, trim are string manipulation functions
which strip or remove whitespaces from the beginning, ending,
or both beginning and ending of a string.
Code:
function trim(id){
var txt = document.getElementById(id);
var str = txt.value.replace(/^\s+/, '').replace(/\s+$/, '');
return str;
}
function ltrim(id){
var txt = document.getElementById(id);
var str = txt.value.replace(/^\s+/, '');
return str;
}
function rtrim(id){
var txt = document.getElementById(id);
var str = txt.value.replace(/\s+$/, '');
return str;
}
See sample output below:
Input Text Here:
Output:
0 comment/s:
Post a Comment