Only Numaric Input for Javascript (jQuery)


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

Use:

$(document).ready(function(){
$("#input").forceNumeric();
});


Copy this code and paste it in your HTML
  1. jQuery.fn.forceNumeric = function() {
  2. $(this).keydown(function(event){
  3. if( event.keyCode == 46 || event.keyCode == 8 || (event.keyCode < 41 && event.keyCode > 36) || (event.keyCode < 58 && event.keyCode > 47) || (event.keyCode < 106 && event.keyCode > 94) ){
  4. }else{
  5. event.preventDefault();
  6. }
  7. });
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.