Alex Rivera | Logout

How do I block or restrict special characters from input fields with jquery?

Asked 2009-05-21T22:50:42.293
152

How do I block special characters from being typed into an input field with jquery?

Edit
Report

1 Answer

2

Just the numbers:

$('input.time').keydown(function(e) {
    return e.keyCode >= 48 && e.keyCode <= 57);
});

For time including : replace 57 with 58. To also include delete and backspace:

return (e.keyCode >= 46 && e.keyCode <= 58) || e.keyCode == 8;
answered 2012-07-30T14:18:32.457

Your Answer