Here's an idea:

<label for="foo" class="validate 000h000h00"></label>
<input name="foo" id="foo" type="text" />

It's HTML 4.01, will probably pass for strict, and it semantically
separates the validation from the field.  The idea is that for every label
with class "validate", there's a validation mask somewhere within the
classes that should be applied to the associated field.  This can
conceivably apply to any input, if you want to do the work.  This could
guarantee a set number of checkboxes are checked, one of the radio buttons
has been chosen, a select is not left on its default value, etc.

Some gotchas:
* The only legal place to put the mask would be as a class.  It would be a
Bad Thing if you tried to make it the ID, since each element should have
only one unique ID, and you may want to apply the same mask to a different
field.  The bonus here is that you can also style by validation mask.  How
cool would that be?  (e.g.: Use a background-image of a phone icon for
fields that want a phone number.)

* One would need to create a language for expressing a mask using only
alphanumerics and underscores, since that's what's legal in a class. 
This, in turn, may require enough regexp magic to make the best of us go
running for the aspirin bottle.  :)

* One would need to support two legal HTML syntax cases - <label
for="foo"> and <label><input /></label> .

* For broken use cases (e.g.: class="validate" -- no mask is provided),
one would want to bail out silently rather than throwing an error.

What do you think?  I'm almost feeling crazy enough to take a whack at it.
 It all starts with $("label"), how hard could it be?  :)

- Brian


>> And the using it like this:
>> <input validate="pattern:###-###-##" />
>
>
> And I still vote for doing in a standards compliant way...
>
>
> -- Klaus
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to