ASP.NET like ValidationGroup using JQuery validate plugin?

2.5k Views Asked by At

We're trying to get the JQuery validate plugin working on our site but we've stumbled across a problem here.

On our site we have a login form available for the user on every page where we'd like to use the plugin to validate that the user has entered a username and password.

We also have a couple of pages showing for instance some kind of form which we'd also like to validate using the validate plugin.

The problem we've seen is that there is no way to group the username and password textbox to the login button and all the textboxes and stuff in the other form to that form's submit-button. If we'd use the ASP.NET validator we'd use the ValidationGroup attribute but I haven't found a good solution for this using JQuery yet.

1

There are 1 best solutions below

1
On

http://docs.jquery.com/Plugins/Validation

What you need to do is call the following code where "#myForm" is the ID of the form you're trying to validate:

  $(document).ready(function(){
     $("#myForm").validate();
  });

Your form would look like this:

     <form  id="myForm" method="get" action="">
         Name
         <input id="cname" name="name" size="25" class="required" minlength="2" />
         E-Mail
         <input id="cemail" name="email" size="25"  class="required email" />
         <input class="submit" type="submit" value="Submit"/>
     </form>

Each form you run validate() on will automatically cause validation when the submit button is clicked on it.