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

[whatwg] pattern attribute

From: Ian Hickson <ian@hixie.ch>
Date: Sat, 21 Aug 2004 11:39:27 +0000 (UTC)
Message-ID: <Pine.LNX.4.61.0408211130250.20869@dhalsim.dreamhost.com>
On Thu, 22 Jul 2004, Wrigley, Ave wrote:
> 
> 1. What is the motivation behind the implicit ^ and $ (start and end of 
> string metacharacters)? I appreciate that in a lot of cases it makes it 
> easier for people to implicitly match the whole string, but (as is 
> mentioned in a sidebar) it make it potentially much more complex for 
> people who want to match substrings (especially where newlines are 
> possible). Would it be better just to comply with the ECMA-262 spec?

I just added a note to the document that says:

| The implicit ^ and $ characters are inserted because it is expected
| that the overwhelming majority of use cases will be to require that
| user input exactly match the given pattern. Authors who forget that
| these characters are implied will immediately realise their mistake
| during testing. Had the characters not been implied, requiring most
| authors to insert them themselves, it is likely that authors who
| forgot them would not catch their mistake as easily.


> 2. Also (not wishing to compicate things too much!) did you consider
> supporting regex modifiers (I guess case insensitivity would be
> particularly useful)?

I considered it but I couldn't really see an easy way to do it. If JS
supported perl's scoped modifiers, that would work, but I don't think
it does.


> 3. Finally, is it necessary to have an ERROR_ for invalid regexes

No, if the regexp is invalid, it is just ignored.


> I guess the real point of 1 is consistency, and the expectation that the
> input control will do what you expect. For example - I would expect that
> if I already have a validator implemented in javascript, I should be
> able to use the same regex pattern that I am using to validate an imput
> field in the script.

Most of the time you would, unless your pattern was specifically a
substring search pattern, which seems unlikely.


Thanks for your input!

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Saturday, 21 August 2004 04:39:27 UTC

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