Restrict special characters being entered in textbox using jquery/javascript?

In this tutorial,I will explain how to restrict the special characters being entered in textbox using jquery/javascript.
It is very important to check user input text validity to prevent the sql injection that can harm your database.
Example:Restrict special characters being entered in textbox using jquery/javascript?
<html>
<title>Restrict Special characters in textbox</title>
<head>
 <script language="javascript" type="text/javascript">
function SpCharcheck(e) {
var num;
var char;
if (window.event)
{
num = e.keyCode
}
else if (e.which)
{
num = e.which
}
char = String.fromCharCode(num)
if (char == "-" ||char == "<" ||char == ">" ||char == "'" || char == "`")
{
return false;
}
else {
return true;
}
}
</script>
</head>
<body>
<input type="text" name="emp_name" id="emp_name" onkeypress="return SpCharcheck(event)"> 
</body>
</html>