HTML input for Positive Whole Numbers Only (Type=number)

前端 未结 9 2037
悲&欢浪女
悲&欢浪女 2020-12-09 02:29

I can\'t find the right regex pattern for this, even though there are a lot of questions in this kind.

I dont want the user to be able to type or input



        
9条回答
  •  無奈伤痛
    2020-12-09 03:10

    It is best to use following in input field, it will stop you to enter any other character except whole numbers.

    Only whole number will be accepted.

    onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57"
    

    See demo

提交回复
热议问题