W3C home > Mailing lists > Public > whatwg@whatwg.org > June 2004

[whatwg] Re: Various attributes

From: Malcolm Rowe <malcolm-what@farside.org.uk>
Date: Thu, 17 Jun 2004 10:12:40 +0100
Message-ID: <courier.40D16088.0000598A@mail.farside.org.uk>
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 
Received on Thursday, 17 June 2004 02:12:40 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:34 UTC