Posted By

vagrantradio on 06/04/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jillella


Numeric Only jQuery Plugin


 / Published in: jQuery
 

  1. //usage
  2. $("#yourTextBoxName").ForceNumericOnly();
  3.  
  4. //plugin
  5. jQuery.fn.ForceNumericOnly =
  6. function()
  7. {
  8. return this.each(function()
  9. {
  10. $(this).keydown(function(e)
  11. {
  12. var key = e.charCode || e.keyCode || 0;
  13. // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
  14. return (
  15. key == 8 ||
  16. key == 9 ||
  17. key == 46 ||
  18. (key >= 37 && key <= 40) ||
  19. (key >= 48 && key <= 57) ||
  20. (key >= 96 && key <= 105));
  21. })
  22. })
  23. };

Report this snippet  

You need to login to post a comment.