Registration form validation using jQuery

Please follow & like us :)

jquery logo

JQuery is a javascript library and widely used on the websites as it provides most of the functionalities with just few lines of code. It is also compatible to legacy browser as well. 

Step 1:

Place the javascript files within the head section

<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=”optional”
Email field -> class = “required email”

Sample Code:

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.

Here is the playable code editor where you can test the validation!