Guest User

Untitled

a guest
May 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. $(".numberinput").forceNumeric();
  4. });
  5.  
  6. // forceNumeric() plug-in implementation
  7. jQuery.fn.forceNumeric = function () {
  8. return this.each(function () {
  9. $(this).keydown(function (e) {
  10. var key = e.which || e.keyCode;
  11.  
  12. if (!e.shiftKey && !e.altKey && !e.ctrlKey &&
  13. // numbers
  14. key >= 48 && key <= 57 ||
  15. // Numeric keypad
  16. key >= 96 && key <= 105 ||
  17. // comma, period and minus, . on keypad
  18. key == 190 || key == 188 || key == 109 || key == 110 ||
  19. // Backspace and Tab and Enter
  20. key == 8 || key == 9 || key == 13 ||
  21. // Home and End
  22. key == 35 || key == 36 ||
  23. // left and right arrows
  24. key == 37 || key == 39 ||
  25. // Del and Ins
  26. key == 46 || key == 45)
  27. return true;
  28.  
  29. return false;
  30. });
  31. });
  32. }
  33. </script>
  34. <div class="containercontent">
  35. <div class="label">Enter a number:</div>
  36. <input type="text" name="txtNumber1" id="txtNumber1" value="" class="numberinput" />
  37.  
  38. <div class="label">Enter a number:</div>
  39. <input type="text" name="txtNumber2" id="txtNumber2" value="" class="numberinput" />
  40. </div>
Add Comment
Please, Sign In to add comment