Blog

How to block symbols in a textbox using Jquery

Posted by : Leo T Abraham on 14 January, 2014

Assign the class symblock to the text field in which you want to block symbols and use the following function, to block symbols using Jquery.

$(function() {
    $('.symblock').keydown(function(e) {
        if (e.shiftKey || e.ctrlKey || e.altKey) {
            e.preventDefault();
        } else {
            var key = e.keyCode;
            if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                e.preventDefault();
            }
        }
    });
});