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

前端 未结 2 905
温柔的废话
温柔的废话 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:07

    Citing MDN on the pattern property (highlighting added):

    pattern

    A regular expression that the control's value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is text, search, tel, url or email; otherwise it is ignored. The regular expression language is the same as JavaScript's. The pattern is not surrounded by forward slashes.

    Interestingly I can't find any mentioning of that in both W3C and WhatWG standards.

提交回复
热议问题