Jquery Validate and submitHandler

Jquery Validate and submitHandler

Hi,

I am using jquery.validate, when you specify a function for submitHandler, can you use it to call a method to for example do additional validation and then calling another method to write to the database? I have specified a method in my submitHandler, but I get the error 'invalid label {"d":0}'. Here is my code :

  1. $.validator.setDefaults({
                     submitHandler: function() { addUser(); }
                 });

                 $("form").validate({
                 //errorLabelContainer: $("#divErrors"),
                
                     rules: {
                         txtUserName: {
                             required: true,
                             minlength: 4,
                             maxlength: 20
                         },
                         txtPassword: {
                             required: true,
                             minlength: 4,
                             maxlength: 32
                         },
                         txtConfirmPassword: {
                             required: true,
                             equalTo: "#txtPassword",
                             minlength: 4,
                             maxlength: 32
                         },
                         txtFirstName: {
                            required: true,
                            maxlength: 50
                         },
                         txtLastName: {
                            required: true,
                            maxlength: 50
                         },
                         txtJobTitle: {
                            required: true,
                            maxlength: 100
                         },
                         txtEmailAddress: {
                             required: true,
                             email: true,
                             maxlength: 100
                         },
                         txtTelephoneNumber: {
                             required: true,
                             number: true//,
                             //postalCode:true
                         }
                     },
                     messages: {
                         txtUserName: {
                             required: "Please enter a User Name",
                             minlength: "User Name must be at least 4 characters",
                             maxlength: "User Name must be no more than 20 characters"
                         },
                         txtPassword: {
                             required: "Please enter a Password",
                             minlength: "Password must be at least 4 characters",
                             maxlength: "Password must be no more than 32 characters"
                         },
                         txtConfirmPassword: {
                             required: "Please confirm Password",
                             equalTo: "Confirm Password must match Password",
                             minlength: "Confirm Password must be at least 4 characters",
                             maxlength: "Confirm Password must be no more than 32 characters"
                         },
                         txtFirstName: {
                             required: "Please enter a First Name",
                             maxlength: "First Name must be no more than 50 characters"
                         },
                         txtLastName: {
                             required: "Please enter a Last Name",
                             maxlength: "Last Name must be no more than 50 characters"
                         },
                         txtJobTitle: {
                             required: "Please enter a Job Title",
                             maxlength: "Job Title must be no more than 100 characters"
                         },
                         txtEmailAddress: {
                             required: "Please enter an Email Address",
                             email: "Please enter a valid Email Address",
                             maxlength: "Email Address must be no more than 100 characters"
                         },
                         txtTelephoneNumber: {
                             required: "Please enter a Telephone Number",
                             number: "Telephone Number must be numeric"
                         }
                     }
                 });
             });

             function addUser() {

                 //check for unique username and email
                 $.ajax(
                 {
                     type: "POST",
                     url: "/Services/CDServices.asmx/CheckForUniqueUserName",
                     data: "{strUserName:'" + $('input[name="txtUserName"]').val() + "'}",
                     async: false,
                     dataType: "json",
                     contentType: "application/json; charset=utf-8",
                     success: function(msg) {
                         if (msg.d == 0) {
                             alert("already exists");
                         }
                         else {
                             alert("username is unique");
                         }
                     }
                 });