Removing an Special Characters in the Textbox using JavaScript.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 241
Sometime we might come into a situation to remove the specials characters in the textbox while users feed the
input.Below JavaScript code will help us to remove those special characters from textbox.

<script language = "javascript" type = "text/javascript">
function RemoveSpecialChar(txtVal)
{
if (txtVal.value != '' && txtVal.value.match(/^[\w ]+$/) == null)
{
txtVal.value = txtVal.value.replace(/[\W]/g, '');
}
}
</script>
<asp:TextBox ID = "txtName" onkeyup = "javascript:RemoveSpecialChar(this)" runat = "server">

Comments or Responses

Login to post response