Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Form validation using Jquery

Simple form validation using Jquery.

Embed the below js files:

http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js  
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js

Add below CSS:

.error { border: 1px solid #b94a48!important; background-color: #fee !important; }


Script:

 // When the browser is ready...
  $(function() {

// Setup form validation on the #register-form element
$("#register-form").validate({   //#register-form is form id
   
    // Specify the validation rules
    rules: {
        firstname: "required", //firstname is corresponding input name
        lastname: "required",  //lastname:  is corresponding input name
        email: {               //email is corresponding input name
            required: true,
            email: true
        },
 
    },
   
    // Specify the validation error messages
    messages: {
        firstname: "Enter First Name",
        lastname: "Enter Last Name",
        email: "Enter Valid Email ID",
        agree: "Please accept our policy"
    },
    submitHandler: function(form) {
        form.submit();
    }
});

  });


This post first appeared on PSD-HTML-CSS-JS, please read the originial post: here

Share the post

Form validation using Jquery

×

Subscribe to Psd-html-css-js

Get updates delivered right to your inbox!

Thank you for your subscription

×