Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery - numeric, number only function

0 votes
10 views
added Sep 20 in jQuery by LC Marshal Lieutenant (13,770 points)
jQuery.fn.ForceNumericOnly =
  function() {
      return this.each(function() {
          $(this).keydown(function(e)
          {
              var key = e.charCode || e.keyCode || 0;
              // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
              // home, end, period, and numpad decimal
              return (
                  key == 8 || 
                  key == 9 ||
                  key == 13 ||
                  key == 46 ||
                  key == 110 ||
                  key == 190 ||
                  (key >= 35 && key <= 40) ||
                  (key >= 48 && key <= 57) ||
                  (key >= 96 && key <= 105));
          });
      });
  };
var numericField = $('#edit-profile-basic-field-phone-number-und-0-value, #edit-profile-basic-field-zip-und-0-value, #edit-profile-basic-field-account-number-und-0-value, edit-profile-basic-field-ic-und-0-value ');

$(numericField).ForceNumericOnly();

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...