Home arrow JavaScript arrow Page 3 - Comparing Fields and Customizing Error Messages with jQuery`s Validator Plug-in
JAVASCRIPT

Comparing Fields and Customizing Error Messages with jQuery`s Validator Plug-in


Welcome to the final installment of the series that shows you how to check online forms with the Validator jQuery plug-in. Made up of seven tutorials, this series explores the most useful features that come packaged with this library, and shows you how to use them for performing strict validation on your own HTML forms.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 4
November 10, 2009
TABLE OF CONTENTS:
  1. · Comparing Fields and Customizing Error Messages with jQuery`s Validator Plug-in
  2. · Review: validating numeric values and file extensions
  3. · The equalTo argument
  4. · The showErrors() method

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Comparing Fields and Customizing Error Messages with jQuery`s Validator Plug-in - The equalTo argument
(Page 3 of 4 )

As I said in the section that you just read, the Validator plug-in provides another useful option called “equalTo” that permits you to determine if the values entered into two form fields are equal. Naturally, this feature can be really handy for implementing a password confirmation system, to cite only one example.

But the best way to understand how the “equalTo” option works is by means of a functional example. Below I coded one for you. Take a look at it:

<!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 the equalTo 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: {

username: {

required: true,

maxlength: 10

},

password: {

required: true,

maxlength: 10

},

passwordconfirm: {

required: true,

equalTo: "#password"

}

}

});

});

</script>

</head>

<body>

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

<p>User Name <input type="text" name="username" class="required" /></p>

<p>Password <input type="password" id="password" class="required" /></p>

<p>Confirm Password <input type="password" name="passwordconfirm" class="required" /></p>

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

</form>

</body>

</html>

As shown above, the “equalTo” option has been used to compare the values entered in the “password” and “passwordconfirm” fields of the previous web form. If those are found to be distinct, then an error message indicating this condition will be displayed on screen. Simple and effective, right? However, if you still have some doubts regarding the use of this option, then the following screen capture should help to dissipate them:

Undoubtedly, understanding how the “equalTo” argument does its business is indeed a no-brainer process that doesn’t require any further explanation. Therefore, it’s time to tackle the last section of this tutorial, which will explain how to display customized error messages with the Validator plug-in.

As usual, to learn how this will be done, please click on the link shown below and read the final part of this article.


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 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials