How can I limit possible inputs in a HTML5 “number” element?

前端 未结 26 2917
感动是毒
感动是毒 2020-11-22 05:12

For element, maxlength is not working. How can I restrict the maxlength for that number element?

26条回答
  •  野的像风
    2020-11-22 05:33

    You can combine all of these like this:

    
    
    
    


    Update:
    You might also want to prevent any non-numeric characters to be entered, because object.length would be an empty string for the number inputs, and therefore its length would be 0. Thus the maxLengthCheck function won't work.

    Solution:
    See this or this for examples.

    Demo - See the full version of the code here:
    http://jsfiddle.net/DRSDavidSoft/zb4ft1qq/1/

    Update 2: Here's the update code: https://jsfiddle.net/DRSDavidSoft/zb4ft1qq/2/

    Update 3: Please note that allowing more than a decimal point to be entered can mess up with the numeral value.

提交回复
热议问题