Home arrow JavaScript arrow Page 2 - 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 - Review: validating numeric values and file extensions
(Page 2 of 4 )

It’s possible that you still haven’t read the preceding tutorial, where I explained how to use the “number” and “accept” options provided by the Validator plug-in for checking numeric values and file extensions. Therefore, below I reintroduced the examples created in that article, which show a simple use of these arguments. Here they are:

(example on using the ‘number’ option)

 

<!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 number 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,

maxlength: 5

},

lname: {

required: true,

maxlength: 5

},

email: {

required: true,

email: true

},

age: {

required: true,

number: true

}

}

});

});

</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>Age <input type="text" name="age" class="required" /></p>

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

</form>

</body>

</html>

 

 

(example on using the ‘accept’ option)

 

<!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 accept 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,

maxlength: 5

},

lname: {

required: true,

maxlength: 5

},

email: {

required: true,

email: true

},

avatar: {

required: true,

accept: "jpg|gif|png"

}

}

});

});

</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>Avatar <input type="text" name="avatar" class="required" /></p>

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

</form>

</body>

</html>

As you can see, the first code sample illustrates how to use the “number” option to check if a value entered in a specific form field is numeric or not, while the last example shows a simple usage of the “accept” argument for filtering some common graphic file extensions.

At this point, you hopefully grasped how the previous examples work, so it’s time to see how to utilize the capabilities of the Validator plug-in to determine whether the values assigned to two fields of an HTML form are the same.

If you wish to learn the full details of this process, then click on the link that appears below and read the next section.


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