title: Custom validation with ajax.....Here remote method is not working
body: <p>I am using jquery.validate.js, in the code below both remote and regex works separately but when I try to integrate both then it is not working. Can anybody help me where I did wrong? </p>
  
  <pre><code>    &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  
  
  $(document).ready(function(){
  
          $("#clear").click(function(){
  
              $("input[type=text], textarea").val("");
  
          });
  });
  
  function submitForm() {
  
      $.validator.addMethod("subTitleVal", function(value, element) {
          return this.optional(element) || /^[A-Za-z\s\_,\.:;()''""]+$/.test(value); 
      }, "Enter Valid Name.");
  
      var validator = $("#company").validate({
          errorPlacement : function(error, element) {
              offset = element.offset();
              error.insertBefore(element)
              error.addClass('message'); 
              error.css('position', 'absolute');
              error.css('left', offset.left + element.outerWidth());
          },
          rules : {
              name : {
                  required : true,
                  subTitleVal : true,
                        remote: {
                          type: 'POST',
                          url: "${pageContext.request.contextPath}/company/getDuplicate",
                          data: {"name":name},
                          dataType : "json",
                          success:function(data){
                              /* response = ( data == true ) ? true : false; */
                              if (data.name == true)
                              {
                                  message: {
                                      name: 'The username is already in use!'
                                  }
                              }
                          }
                      },
                  }
                  },
          },
          errorElement : "span",
          wrapper : "span",
          messages : {
              name : {
                  required : "Name Is Required",
              }
          }
      });
      if(validator.form()){ 
          $('form#company').submit(); 
          }
  };
  
  &lt;/script&gt;
  
     &lt;/head&gt;
     &lt;body&gt;
   &lt;form:form commandname="company" action="${pageContext.request.contextPath}/company/create.action"  method="post" modelAttribute="company" name="theform"&gt;
  
      &lt;label&gt;Name:&lt;/label&gt;
      &lt;form:input path="name" id="name"&gt;&lt;/form:input&gt;
  
      &lt;a href="Javascript:submitForm()"&gt;Add&lt;/a&gt;
  
  &lt;/form:form&gt;
  
  &lt;/body&gt; 
  </code></pre>
  
  <p>please help. Thanks</p>