The JQuery plugin Validation by bassistance.de is extension, powerful, and quick-to-deploy. I recommend this library for people already using the jQ framework to provide high-quality, usable client-side form validation. We are going to discuss basic properties of this framework as well as AJAX and scalability. Here is the code we are going to step through. This code was specifically designed to create an ajax experience for the medical technology company eMedTV.com. The live example can be found at this address.
Here’s my validation function:
$(document).ready(function() {
if (pageName=="researchCenter") {
// Just use a different variable for each form you use. It is too difficult to use just one for all forms because each form has it's own plethora of needs (usually).
var validator = $("#researchCenterForm").validate({
// #messageBox holds the all encompassing message at the top to let all the users know there is a problem.
errorContainer:"#messageBox",
// This is very important for manipulating the placement and styles of the error message for individual cases, such as first name or zip. I'll explain this later.
errorClass: "formError",
// wrapper is only needed if you want to wrap the error message in something. If you want a list the errors it can be a
First thing you’ll probably notice is this plugin is formatted in object oriented programming. So it is very straight forward to know which methods and which properties to use for your form. Once you locate the ultimate guide to how to use the validator, it can become relatively straight forward to use.
How to stylize where error label fields go on the page
CSS:
.formError {
position: absolute;
margin: 21px -13pt 0pt;
}
li {
position: relative;
}
The margin is to position the error label below the form field, such as an email input box. Positioning it absolutely makes sure the forms look and feel is not altered by static elements.
HTML:
You’ll notice the class name “betterEmail” and “required”. This is to enter in jQ validation methods into the html markup itself. Cool huh?
The HTML after the error has been applied in real-time:
Once you have your form all setup you can start writing your own mime types if you include the mime type plugin as well.
Currently the validator checks if your email is alex@alexgrande and that’s it. If you want to make sure there is a .com or .org, etc you need this:
jQuery.validator.addMethod("betterEmail", function(value, element) {
return this.optional(element) || /^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/i.test(value);
}, "Valid Email Please");
See I how I use betterEmail above.
Another is if you have a drop down menu like a select box with options. There isn’t a default way to do this. My solution is the following. Notice the option with the value=”none”.
jQuery.validator.addMethod("selectCountry", function(value, element) {
return this.optional(element) || ( value.indexOf("none") == -1);
}, "Please choose a Country.");
Another problem I have found is if you have three different select boxes, such as month, day, and year and you want only one error message for all three since they are all related. My solution is to make all three error message overlap making it appear they are all the same to the user.
HTML:
CSS:
li#date .formError {
left: 2px;
bottom: -15px;
}
Thus every formError will overlap each other with the same position on the page.
Last problem is fixing error form position issues in IE. That’s easy. If you read my article about handling cross-browser issues then you’ll know most of what to do. Since we positioned the error message absolutely we can position it using IE conditional comments only for IE.
CSS:
.ie li#date .formError {
top: 1000px;
}
This is all for this discussion. If I think of more I’ll add to it later. In either case, please send questions or comments.

#1 by Jörn Zaefferer on May 25, 2008 - 5:46 am
The email validation got fixed in the 1.2.1 release, it now requires the .xxx part. So your betterEmail-method isn’t necessary anymore.
Your select method can be replaced by using a required rule with value=”". That is, replace “none” with an empty string.
The 1.3 release added a “groups” option. In your date-example, you specify this:
groups: { dateGroup: “DOBMonth DOBDay DOBYear” }
Depending on your layout, you still need to specify the message placement using the errorPlacement-option.
I hope that helps. Let me know if you find other issues, I’m sure we can solve those, too.
#2 by Fernando Zanatta on July 2, 2008 - 1:40 pm
Congratulations guy!
It helped me a lot !
Made me not wast time on my own function to do that.
I really apreciate your help.
Thank u a lot !
#3 by Eric on November 2, 2009 - 8:41 am
Hello, thanks for posting this! I checked out your example form and I see you wrote a lot of custom validation rules (you obviously know your stuff!). Anyway you can show how to write a custom validation rule for a textarea, that prevents any url’s (www or http://) from being input? I’m using bassistance.de plugin. Thanks for your time!