Tuesday, September 4, 2018

How to enable user to enter only integer values to the input box using jQuery.


Answer:

Put this code in script tags and you'll be only able to enter only integer values in the input box.

$(document).ready(function(){
    $("input").keyup(function(){
      $(this).val( $(this).val().replace(/[^0-9]+/, '') );
        if($(this).val() == ''){
          $(this).val(0);                                 
        } 
    });
});



No comments:

Post a Comment