HTML5 Form Validation Plugin - Needs Testing and Feedback

HTML5 Form Validation Plugin - Needs Testing and Feedback

A jQuery plugin that understands HTML5 forms and knows how to validate them, even in browsers that don't yet support HTML5.

http://ericleads.com/h5validate/

In browsers that do support HTML5, h5Validate adds some much-needed features, such as the ability to customize the user interface when an input fails validation.

Uses the new "required" and "pattern" attributes in HTML5 to extract validation rules from your HTML and enforce them.

Very configurable:

Available options:

errorClass

Custom CSS class for validation errors.

validClass

Custom CSS class to mark a field validated.

errorAttribute

An html attribute that stores the ID of the error message container for this element. It's set to data-errorID by default. Note: The data- attribute prefix is a new feature of HTML5, used to store an element's meta-data. e.g.

<input id="name" data-errorID="nameError" required >
kbSelectors

A list of CSS selectors for attaching keyboard-oriented events. Default:

kbSelectors: ':text, :password, select, textarea'
focusout, focusin, change, keyup

(Events) These are the "keyboard oriented" events. Better to think of them as non-mouse-specific events. Set them to "true" if you want them to trigger a field validation. Defaults:

focusout: true,
focusin: false,
change: false,
keyup: true


mSelectors

A list of CSS selectors for attaching "mouse oriented" events. Default:

mSelectors: ':radio, :checkbox, select, option'
click

(Event) The only default mouse-oriented event. Since it probably makes little sense to trigger validation on other mouse events, I'll leave it to you to figure out how to enable them.

Note: The click event isn't just for the mouse. It will trigger for keyboard and touch screen interactions, too.

click: true

Coming soon!

submit

(Event) Set true to trigger validation on submit. Submit needs a special handler, because it needs to check that all fields are valid, optionally save data, and optionally submit the form. Will have Ajax, get, and post. Default:

submit: true
patternLibrary

A library of pattern expressions that you can attach with the class attribute, instead of embedding the same pattern many times in your markup. This is good, because you might want to re-use a pattern, and there's only one bug to fix if the pattern needs to be fixed later. Sure beats search and replace!

messages

Error messages to display. This is here so that you can easily swap them out. You might want to write your own error messages, or provide language translations.