Prevent negative inputs in form input type=“number”?

前端 未结 8 944
太阳男子
太阳男子 2020-12-12 16:58

I want to restrict user input to positive numbers in an html form.

I know you can set min=\"0\", however it is possible to bypass this by manually entering a negati

8条回答
  •  遥遥无期
    2020-12-12 17:54

    This uses Javascript, but you don't have to write your own validation routine. Instead just check the validity.valid property. This will be true if and only if the input falls within the range.

    
    
    

提交回复
热议问题