title: A simple jQuery form validation script
body: <p>I made a simple validation form using jQuery. It's working alright. The thing is I'm not satisfied with my code. Is there another way around to write my code with the same output result?</p>
  
  <pre><code>$(document).ready(function(){
  
  $('.submit').click(function(){
      validateForm();   
  });
  
  function validateForm(){
  
      var nameReg = /^[A-Za-z]+$/;
      var numberReg =  /^[0-9]+$/;
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  
      var names = $('#nameInput').val();
      var company = $('#companyInput').val();
      var email = $('#emailInput').val();
      var telephone = $('#telInput').val();
      var message = $('#messageInput').val();
  
      var inputVal = new Array(names, company, email, telephone, message);
  
      var inputMessage = new Array("name", "company", "email address", "telephone number", "message");
  
       $('.error').hide();
  
          if(inputVal[0] == ""){
              $('#nameLabel').after('&lt;span class="error"&gt; Please enter your ' + inputMessage[0] + '&lt;/span&gt;');
          } 
          else if(!nameReg.test(names)){
              $('#nameLabel').after('&lt;span class="error"&gt; Letters only&lt;/span&gt;');
          }
  
          if(inputVal[1] == ""){
              $('#companyLabel').after('&lt;span class="error"&gt; Please enter your ' + inputMessage[1] + '&lt;/span&gt;');
          }
  
          if(inputVal[2] == ""){
              $('#emailLabel').after('&lt;span class="error"&gt; Please enter your ' + inputMessage[2] + '&lt;/span&gt;');
          } 
          else if(!emailReg.test(email)){
              $('#emailLabel').after('&lt;span class="error"&gt; Please enter a valid email address&lt;/span&gt;');
          }
  
          if(inputVal[3] == ""){
              $('#telephoneLabel').after('&lt;span class="error"&gt; Please enter your ' + inputMessage[3] + '&lt;/span&gt;');
          } 
          else if(!numberReg.test(telephone)){
              $('#telephoneLabel').after('&lt;span class="error"&gt; Numbers only&lt;/span&gt;');
          }
  
          if(inputVal[4] == ""){
              $('#messageLabel').after('&lt;span class="error"&gt; Please enter your ' + inputMessage[4] + '&lt;/span&gt;');
          }       
  }   
  
  });
  </code></pre>