validateForm: Validate Form Fields
Client-side form validation should never be an excuse to leave out server-side checking, but having it helps the user save annoying round trips to the server.
This example tries to offer the best of both worlds, by making it easy to incorporate the same regular expressions used on the server. It also offers a way to submit the form's data using AJAX.
The following form validates the filled in contents using little icons. A summary is provided when the submit button is pressed. Fields like the date can contain a template as a hint for the user. It is not validated until actual values are filled in.
The "alphanumeric" test has a custom regular expression to test against, stored in a hidden form field.
Submitted by AJAX
The next example submits itsself using AJAX. The server's reply replaces the form.
The radio buttons and password examples introduce two forms interdependence.
Recalculated using AJAX
The next example submits itsself using AJAX and refreshes the form after every change.
This way the validation-script can be used to support complex server-side functionality.
Required Files
-
jQuery Addon Script: jquery.classbehaviours.validateform.js
- Prerequisite Script: jquery.classbehaviours.js
- Optional Script: jquery.classbehaviours.inputformat.js
- Optional Script: jquery.classbehaviours.fileupload.js
- Optional Script: jquery.classbehaviours.datepicker.js
- Example Markup: validateForm.html
-
Example Stylesheet: validateForm.css
- Optional Stylesheet: inputformat.css
- Optional Stylesheet: fileupload.css
- Optional Stylesheet: datepicker.css
- Example XML / IFRAME: validateForm.xml
Comments on this Article