1

Am trying to disable open and closed parenthesis for a textbox.

Am succesful in disabling keycode for few characters but not with the one uses SHIFT.

 if(event.keyCode == 57 || event.keyCode == 48)

disables both 9 ,0 along with open and closed parenthesis

if (event.shiftKey) {
            if(event.keyCode == 57 || event.keyCode == 48)
            event.preventDefault();
        }

how do i diable parenthesis alone and not numbers. what is the correct way.

i dont want to use any plugins

Thanks

Peru
  • 2,871
  • 5
  • 37
  • 66
  • 1
    Works for me: http://jsbin.com/ahized/1 ([source](http://jsbin.com/ahized/1/edit)). But you should probably use `event.which`, not `event.keyCode`, see [the docs](http://api.jquery.com/category/events/event-object/) for details. – T.J. Crowder Apr 29 '13 at 06:09
  • See http://stackoverflow.com/a/7975890/2235132 – devnull Apr 29 '13 at 06:10

1 Answers1

3
$('input').on('keypress', function(e) {
    if (e.which == 40 || e.which == 41)
        e.preventDefault();
});

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388