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">