Allowing only numbers and one decimal

后端 未结 6 1938
醉梦人生
醉梦人生 2020-12-19 17:58

Guys and gals i have this piece of JavaScript code that only allows for numbers and one decimal period. The problem i\'m having is that when i tab over to my textbox contro

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 18:39

    Be sure to test on any browser. The accepted answer doesn't work on Firefox.

    Try HTML5 type number:

    
    

    You could define min="0" max="10"

    Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Controlling_input_size

    Note: type="number" is not supported in Internet Explorer 9 and earlier versions.

提交回复
热议问题