JQuery validation

fields           

              Password:                          

          

              OpenID:                          

          

              Have OpenID:                          

          

                         

         

I want to validate this form using jQuery. I want that in case the checkbox is checked the password should be checked, in case it is not checked the openid should be checked. I've tried this:

$().ready(
   function()
   { 
       $("#account").validate
       (
        {
            errorLabelContainer: $("ul", $('div.error-container')),
            wrapper: 'li',

            rules:
            {
                Password:
                {
                    required: true,
                    minlength: 6,
                    maxlength: 20
                },

                OpenID:
                {
                   required: true,
                   minlength: 6
                }
            },

            messages:
            {
                Password:
                {
                    required: "Enter password.",
                    minlength: "Min length is 6.",
                    maxlength: "Max length is 20."
                },

                OpenID:
                {
                   required: "Enter open id.",
                   minlength: "Min length is 6"
                }
             }
          }
       )
  }

      

);

This code ignores whether the checkbox is checked or not. I know of a
function http://docs.jquery.com/Plugins/Validation/Methods/required#dependency-callback that can be applied to the required rule, but it works with the required rule. How can I validate the form?

+1


a source to share


1 answer


you can add a method, your function that checks it jQuery.validator.addMethod



+1


a source







All Articles