Wednesday, August 22, 2007

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

<html>
<head>
<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;
document.getElementById('txt1').focus();
}
</script>
</head>
<body>
<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();' />
</body>
</html>


No comments: