How to make type=“number” to positive numbers only

后端 未结 17 2414
既然无缘
既然无缘 2020-11-30 17:12

currently I have the following code


it comes out to something like this

17条回答
  •  情歌与酒
    2020-11-30 17:52

    I cannot find the perfect solution as some work for inputting but not for copy&paste, some are the other way around. This solution works for me. It prevents from negative number, typing "e", copy&paste "e" text.

    create a function.

    
    

    add these properties to input. this two prevent from copy&paste non-number text, including "e". you need to have both together to take effect.

    
    

    If you are using Vue you can refer this answer here. I have extracted it to a mixin which can be reused.

提交回复
热议问题