Home arrow JavaScript arrow Page 4 - Checking Online Forms with the Validator jQuery Plug-in
JAVASCRIPT

Checking Online Forms with the Validator jQuery Plug-in


If you consider form validation applications to be the kind of coding you least look forward to, keep reading. Thanks to the Validator jQuery plug-in, validating form input from users just got a lot easier. This seven-part series will show you the ways you can use the plug-in to help you build form validation scripts much faster than you may have thought possible.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
October 23, 2009
TABLE OF CONTENTS:
  1. · Checking Online Forms with the Validator jQuery Plug-in
  2. · A simple online form
  3. · Validating the HTML form
  4. · Validating web forms selectively

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Checking Online Forms with the Validator jQuery Plug-in - Validating web forms selectively
(Page 4 of 4 )

In the previous section, you learned how to perform basic validation on all of the fields of a basic contact form. Nonetheless, as I stated before, the Validator plug-in is flexible enough to check the validity of only specified fields. In other words, it permits you to validate forms selectively.

To demonstrate how this process works, below I created a whole new code sample, which will require only that the first two fields of the form be populated with some values, while the third one will simply be ignored.

The example in question is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example on validating web form with minlength argument</title>

<script src="jquery.js" type="text/javascript"></script>

<script src="jquery.validate.js" type="text/javascript"></script>

<script>

$(document).ready(function(){

$("#sampleform").validate({

rules: {

fname: {

required: true,

minlength: 2

},

lname: {

required: true,

minlength: 2

},

email: {

required: false

}

}

});

});

</script>

</head>

<body>

<form id="sampleform" method="post" action="process_form.php">

<p>First Name <input type="text" name="fname" class="required" /></p>

<p>Last Name <input type="text" name="lname" class="required" /></p>

<p>Email Address <input type="text" name="email" class="required" /></p>

<p><input type="submit" value="Submit" /></p>

</form>

</body>

</html>

Here you have it. Now, by specifying a new "rules" argument within the "validate()" method, it's feasible to indicate which fields will be mandatory. In addition, there's another parameter called "minlength" that will require the obligatory fields to be at least two characters long, in this way refining the selective validation process even more.

With this last hands-on example I'm completing this first tutorial of the series on using the handy Validator jQuery plug-in to check online forms. As usual, feel free to copy and edit all of the code samples developed in this article, so you can acquire a better background in the basic features provided by the plug-in.

Final thoughts

In this first chapter of the series, I introduced you to working with the Validator jQuery plug-in, which makes checking web forms a truly no-brainer process. Nevertheless, I'm only scratching the surface when it comes to exploring all of the helpful features that have been packaged with this plug-in. Therefore, in the forthcoming part, I'll be discussing in more detail the use of the "minlength" argument and a few others that allow you to refine the whole validation process.

Now that you've been properly warned, don't miss the next article!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials