working with numeric input field in js

2019-06-12 07:44发布

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.

1条回答
Animai°情兽
2楼-- · 2019-06-12 08:24

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

查看更多
登录 后发表回答