How to use a pattern on an input[type=“number”]?

前端 未结 2 897
温柔的废话
温柔的废话 2021-01-21 07:30

I want the default value to be 0 and recolor the input if it\'s more than 0, using :valid. Am I doing something wrong? Is Google Chrome wrong? Or the HTML5 specific

2条回答
  •  深忆病人
    2021-01-21 08:16

    I see that if you give the minimum value of 1, the color is not green for 0. The color changes to green when you enter 1. I think that is what you are expecting, right?

    Basically, you can use min and max values for validation purpose. I don't think you need pattern for this.

    
    

    There is one limitation here. If you leave the field empty, it is still green!

提交回复
热议问题