[jQuery] Plugin for client-side form validation
Hi jQuery list,
I had some thoughts on js powered form validation. My base idea is this:
<script>
$(#formToValidate).validate();
</script>
<form id="formToValidate" ...>
Username: <input name="username" validate="required" .../>
Address: <input name="address" validate="minlength#3 maxlength#25" .../>
Stuff: <input name="stuff" validate="length#3#25" .../>
E-Mail: <input name="email validate="email" .../>
</form>
The validate plugin would the search for all input elements (including textarea and selects), check the validate attribute and apply the given validators. The "name#parameter" syntax would allow to pass one or more parameters, eg. "minlength#3" to validate an input of at least 3 characters.
I didn't write any code yet, as there are several points that bother me:
- "validate" is no official HTML attribute. Is there any 'legal' attribute that could be used without breaking other functionality? Eg. by using the class attribute it would be easy to break styles. "rel" is only available to link- and a-tags, therefore not a good choice either. I did'nt find a good one in the XHTML specs. Any ideas?
- How to pass error messages to the validation? Put them in the validate attribute when the page is generated (I'd prefer a multi language mechanism)? Load them via AJAX (or AHAH)?
Another thing I didn't work on is outputting error messages. 'alert' is not my personal favorite. I'd definitly love to use fadeIn for error messages scrolling down from the input element :o
Has anyone worked on or knows about something similar? Please let me know :-)
-- Jörn
--
Echte DSL-Flatrate dauerhaft für 0,- Euro*!
"Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/