Hi chetan,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
View
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#txtName').on('keyup', function (e) {
if (e.keyCode == 32) {
alert('White Space not allowed!');
} else if (e.keyCode == 222) {
alert('apostrophe ( ' + e.key + ' ) not allowed!');
}
});
});
</script>
<%:Html.TextBox("txtName") %>
</body>
Screenshot