In this tutorial you will learn how to restrict the special characters being entered in textbox. Sometimes you want to restrict some special characters being entered in textbox of form to prevent the sql injection that can harm your database very badly. So Let's have a look over how to do so.
Now let's have a look over how to call this special characters restriction function in a textbox.
For aspx server side textbox control
<asp:TextBox ID="txtName" runat="server" onkeypress="return check(event)" ></asp:TextBox>
For html textbox control
<input type="text" name="txtName" id="txtName" onkeypress="return check(event)">
You can restrict any other character or number other than special characters too, just by simply add it in the list of characters to be restricted such as for example I want to restrict the character a too then the code will be
if (keychar == "'" || keychar == "`" || keychar == "a")