Posted By

itsmeameer on 03/10/12


Tagged

jquery numaric javascipt


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

itsmeameer
BrockSamsom


Only Numaric Input for Javascript (jQuery)


 / Published in: jQuery
 

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

  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  

You need to login to post a comment.