Numeric Only jQuery Plugin


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.