Thursday, August 23, 2007

Remove Space At Beginning Of The String Using Regular Expression (Left Trim)

<html>
<head>
<script language="javascript">
function Right_Trim()
{
var str = document.getElementById('txt1').value;
str = str.replace(/^\s+/g,'');
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 Beginning Of The String' onclick='Right_Trim();' />
</body>
</html>

No comments: