0

i have a form in wich i have several input... one of them should be a number input type.

i use this code to get only numeric input in a input type.

<script type="text/javascript">
    function isNumberKey(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if ((charCode > 31) && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }
</script>

but i need another features that i still not able to "create"...

i have an input type (example : ) and onkeyup event i call this function (isNumberKey - allowing only numeric input). in case the number wrote is composed by 4 or more numbers i'd like to return (on the same input) the string with the dot notation every 3 number... ex. 900->900 but 1234 -> 1.234 or 15000 -> 15.000.

  • Please make it clear, your question is not clear. – Shivam Feb 24 '14 at 09:59
  • i have an input type (example : ) and on key up event i call this function (isNumberKey). in case the number wrote is composed by 4 or more numbers i'd like to return the string with the dot notation every 3 number... ex. 900->900 but 1234 -> 1.234 or 15000 -> 15.000. – user3346059 Feb 24 '14 at 10:03
  • you should seperate both processes - (1)filtered input and (2)formatting. I think you should format numbers as soon as the component looses focus or the user hits enter. you can use number formatting tools already available. look for instance [here](http://stackoverflow.com/questions/1068284/format-numbers-in-javascript) and [here](http://stackoverflow.com/questions/7327046/jquery-number-formatting) – Jakob Hohlfeld Feb 24 '14 at 10:09

1 Answers1

0

This might be the answer of your question to make the input strictly numeric and allow .(dot) with it.
Make your show the number insert with a dot every 3 number, like this : 100000 -> 100.000. how? part of question clear

UPDATE
Though not a perfect solution try this fiddle
Reference

Community
  • 1
  • 1
Bhavik
  • 4,836
  • 3
  • 30
  • 45
  • i want to show something like this...the user can write only number in this input type (i use the "number" type, but i see that not all the browser supper this html5 feature). so i use the function above, to allow only the numeric input. also i'd like to show to the user that every "thousand" the input type "change" and i add a "dot" on the number....creating something like this : input 1 -> return 1 input 10 -> return 10 input 100 -> return 100 input 1000 -> return 1.000 – user3346059 Feb 24 '14 at 10:10
  • do you mean separate thousand's... By `.(dot) or ,(comma)`..? – Bhavik Feb 24 '14 at 10:13
  • yes i mean this...sepate by .(dot) (by is this really relevant if dot or comma..? o_O) – user3346059 Feb 24 '14 at 10:15
  • thanks everybody, i find this: http://www.mredkj.com/javascript/numberFormatPage2.html – user3346059 Feb 25 '14 at 13:40