[whatwg] Why isn't the "pattern" attribute applied to <input type="number">?

Jukka K. Korpela jkorpela at cs.tut.fi
Fri Feb 10 02:59:10 PST 2012


2012-02-10 12:39, brenton strine wrote:

> Regarding the an input with type in the "number" state, the spec states
> that the "pattern" attribute "must not be specified and do[es] not
> apply to the element".

That’s because the pattern attribute is for constraining text data using 
a regular expression.

> Why is it specifically blocked? Doesn't that encourage the use of a less
> semantic "text" input type for numbers that need to be validated beyond
> simple max and min?

A regular expression, which operates on texts, is not a _logical_ way to 
set constraints on _numbers_. A number is a mathematical entity; a 
numeral, such as 2000 or 2.000 or 2,000 or MM, is a textual presentation 
of a number.

At a more concrete level, type="number" really means type="spinbox", but 
modern design of markup languages favors names that look more semantic. 
(If type="checkbox" were invented today, it would probably be called 
type="boolean".)

> What if you want the number to be either 13 or 16 digits long, as with a
> credit card
>
> pattern="(\d{5}([\-]\d{4})?)"

Then you use type="text". Whether the value is a number or just a 
sequence of digits is debatable. But in any case you don’t want to 
create a spinbox.

Yucca




More information about the whatwg mailing list