jQuery Numeric Only Text Field

by Paul Zepernick

HTML

<input type="text" name="test" class="numeric-only" />

JavaScript

$(document).on('keyup', '.numeric-only', function(event) {
   var v = this.value;
   if($.isNumeric(v) === false) {
        //chop off the last char entered
        this.value = this.value.slice(0,-1);
   }
});