views:

371

answers:

2

There are many solutions suggested on Stack Overflow but i have not found yet, one that fully satisfy my requirements.
I was using Jquery Numeric plugin but i found that is not working (does not allow pasting) on FireFox 3.6 on Osx.

I'm searching a Jquery plugin or Javascript snippet that allow just Numeric Text on a Input Text field.
I have these requirements:

  1. Should allow just numeric text
  2. Should NOT allow punctuation (.,)
  3. Should NOT allow dashed text (-)
  4. Should allow pasting just for numeric text
  5. Multibrowser
  6. Multiplatform
+6  A: 
aSeptik
Good job, it does not work with Firefox 3.6 on OSX.
systempuntoout
i can't test it bro! i don't have a MAC and I'll never have one! ;-) can you tell me what exactly doesn't work!? grazie! ;-)
aSeptik
It does not allow pasting.Grazie a te :).
systempuntoout
ok, updated one more time, now it use `e.ctrlKey` instead of `key code 17`, not sure, but it should work as expected! let me know!
aSeptik
it does not work :(,same problem.+1 for the effort :).
systempuntoout
hey bro, no problem, at this point, i want make it to work, but i need a little help! can you alert() the k var and see what number it give to you!?
aSeptik
I see 224.Sorry for the delay but i was in vacation.
systempuntoout
hey bro! try this new fix and let me know!
aSeptik
jQuery normalizes `event.which` -- so your `Key` function is not necessary: http://api.jquery.com/event.which/
J-P
@J-P: have you tested it in all browser personally!?
aSeptik
For those who care, here's a minified version: http://jsbin.com/icate
Matt Ball
@aSeptik it does not work, thanks for your effort mate.
systempuntoout
+1  A: 

Thanks to dev-null-dweller i have resolved with this script:

jQuery('#input').bind('keyup blur',function(){ 
   jQuery(this).val( jQuery(this).val().replace(/[^0-9]/g,'') ); }
);
systempuntoout
+1 very cute and fast! ;)
aSeptik