[whatwg] Re: Various attributes
Malcolm Rowe
malcolm-what at farside.org.uk
Thu Jun 17 02:12:40 PDT 2004
Jim Ley writes:
>> I disagree - pattern="[0-9]{4}" is significantly more common than
>> something like pattern=".*foo.*", and seriously, how much extra work
>> was the latter?
> Oh, right, can Pattern not work on fields that can contain newlines
> then, I misunderstood, I thought it could, that's not so useful then.
Ah, ok, good point, and good question: I'm not sure. If it can, you're right
that '.*' won't be sufficient to match the start. I'd imagine that most
fields would be single-line, though, so this might not be such a problem.
> In any case "^[0-9]{4}$" and "foo" were my suggestions, both are
> equally simple as the above.
Yes, they are.
The main arguments for providing an implicit ^$-wrapping around a pattern
regexp are that:
* In all other environments I've used (by which I mean, primarily, 'form
designing applications'), patterns specify the contents of the whole field.
Admittedly, this is probably because they don't support regexps, but your
average user would expect a pattern of '[0-9][0-9]' to restrict entry to
being a two-digit number, not a string containing a two-digit number.
* Providing an implicit wrapping means that if the designer is expecting the
pattern to behave as a 'standard' regexp, it will immediately fail. Not
providing a wrapping means that if the designer is expecting the pattern to
behave as a 'whole-pattern' regexp, it will appear to succeed, but it won't
be working as expected.
As a table:
Designer expects pattern to be:
a whole-field pattern (common?) | a standard regexp
No implicit wrapping | Appears to succeed, but doesn't | OK
Implicit wrapping | OK | Fails immediately
* Whole-pattern restrictions are used significantly more frequently that
partial-match restrictions in forms-based applications, from what I've seen.
Regards,
Malcolm
More information about the whatwg
mailing list