Jquery validation using plugin

Posted by Susanthampy under jQuery category on | Points: 40 | Views : 3282
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="Javascript/jquery.validate.js"></script>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
<script type="text/javascript">
$(document).ready(function() {


<form class="cmxform" id="commentForm" method="get" action="">
<legend>A simple comment form with submit validation and default messages</legend>
<label for="cname">Name</label>
<em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" />
<label for="cemail">E-Mail</label>
<em>*</em><input id="cemail" name="email" size="25" class="required email" />
<label for="curl">URL</label>
<em> </em><input id="curl" name="url" size="25" class="url" value="" />
<label for="ccomment">Your comment</label>
<em>*</em><textarea id="ccomment" name="comment" cols="22" class="required"></textarea>
<label for="phone">Phone</label>
<em>*</em><input id="cphone" name="phone" size="20" class="required number" minlength="10" maxlength="10" />
<input class="submit" type="submit" value="Submit"/>


This plugin is very useful for validating controls...

Just add the reference( <script type="text/javascript" src="Javascript/jquery.validate.js"></script>).

After that we can use it.
Eg: class="required number"

Required represents it is a required field and number represents this field only accept numbers...

Comments or Responses

Posted by: Akiii on: 6/7/2011 Level:Bronze | Status: [Member] | Points: 10
hi susan..
nice one.....

Posted by: Susanthampy on: 6/8/2011 Level:Bronze | Status: [Member] [MVP] | Points: 10
Thank u Akiii
Posted by: CS1401 on: 7/4/2011 Level:Starter | Status: [Member] | Points: 10
Nice article

Login to post response