Registration form validation using jQuery

jquery logo

Step 1:

Place the javascript files within the head section

Sample Code
1
2
3
4
5
6
7
8
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script>
$(document).ready(function(){
$("#registerForm").validate();
});
</script>
</head>

You should set the name and id of your html form same as $(“#registerForm”).validate();

Step 2:

For each required form element just place class=”required” and specify minlength tag inside it. For example

Name field -> class=”required”
Email field -> class = “required email”

Sample Code
1
2
3
<input name="name" type="text" id="name" class="required">
<input name="user_id" type="text" id="user_id" minlength="4">
<input name="user_email" type="text" id="user_email" class="required email">

Thats it! you will be able to validate form field textboxes without any advanced code.
For optional fields, you can specify class=”optional” or just leave it.