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

前端 未结 9 2042
悲&欢浪女
悲&欢浪女 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条回答
  •  -上瘾入骨i
    2020-12-09 03:01

    I tried a lot of different solutions to achieve this, and I finally came up with this one, which does the job perfectly for us. It works for typing and for copy/paste, and I couldn't find any unwanted side-effects.

    It is like Nikhil Mahirrao's solution, but it will cause invalid keystrokes to be simply ignored without emptying the input.

提交回复
热议问题