title: ajax form validation before submit how?
body: <p>I am doing ajax cross domain request to my php page on server.
  I am posting form from html via ajax to my php page on server.
  Have problem with validation in client side. </p>
  
  <p>I don't know how to do validation in client side before send form.</p>
  
  <p>html form is standard form, posting input fields: name, last name, message....
  My html form, client side:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      var output = $('.nesa');
  
       $(document).ready(function(){
       $("#form1").submit(function (e) {
       e.preventDefault();
  
      $.ajax({
          url: 'http://www.example.com/form.php',
          crossDomain: true, //set as a cross domain requests
          type: 'post',
          data: $("#form1").serialize(),
          beforeSend: function (){
          // add spinner
           $('.spinner').append('&lt;img id="animacija" src="spinnersmall.gif" alt="Loading" /&gt;');
                     },
  
          success: function (data) {
              $(".nesa").html(data);
              alert("sent " + data);
  
          },
  
          error: function(){
  
              output.text('Message is not sent!');
  
          }
  
      });
  });
  
  });
  </code></pre>
  
  <p>How to to validation? I try to put code in beforeSend but without success.
  Or maybe to use submitHandler? </p>
  
  <p>Idea is when user click submit, that validation start, and if fails to tell "insert your email address". Now when i click submit it send data to server. I want that first check input fields.</p>
  
  <p>This form is actual working it sending data to server, but just need to figure out how to do validation. Where to put validation in ajax call? </p>
  
  <p>Thanks</p>