Skip to Menu

Allows only valid characters to be put in a text box. Can take negative numbers and a decimal point.

Download source code


$("input.numeric").numeric()


No pasting $("input.numeric2").numeric(null, false)


"," decimal separator $("input.numeric3").numeric(",")


"," decimal separator, no pasting $("input.numeric4").numeric(",", false)


Even works in textarea's. $("textarea.numeric").numeric();

Limitations / Bugs

  • Does not validate (best left for another script)
  • Cannot make the number negative if there is already text inside the input box
  • Not all pasting is disabled (except in IE). Shift+Ins works in Opera and context-menu paste works in Opera and Firefox

Fixed bugs

  • Setting allowPaste to true or false makes no difference in Internet Explorer (paste is always allowed)
  • Some characters are let through as they share their character code with other keys:
    • # = 35 = end
    • $ = 36 = home
    • % = 37 = left
    • ' = 39 = right
    • . = 46 = delete
  • Because of the above issue, the delete button does not work when using a . as the separator and there is already one in the text box.