Wednesday, August 22, 2007

Removing The White Space In The String At The End Using Regular Expression (Right Trim)

<script language="javascript">
function Left_Trim()
var str = document.getElementById('txt1').value;
alert(str.length);// Alert To Show The Length Of The String Before Removing White Space
str = str.replace(/\s+$/g,'');
alert(str.length); // Alert To Show The Length Of The String After Removing White Space
document.getElementById('txt1').value = str;
<input type='text' id='txt1' value='Click To Check ' /> <input type='button' id='bt1' value='Remove Space At End Of The String' onclick='Left_Trim();' />

No comments: