title: How to Improve jquery function
body: <p>I'm doing a validation and it's working fine, but I have so many repeat code and can´t find a way to improve it. Here is:</p>
  
  <pre><code>function validate( active ){
  
      if( active[0].id === "mod_formSteps-1" ){
  
          var $inputs = $("#formSteps-1 :input:not(:submit)");
          var value = true;
  
          $inputs.each(function() {
              if( $(this).val().length &lt; 1 || $(this).hasClass("error")){
                  value = false;
              }
          });
          return value;   
      }
      else if( active[0].id === "mod_formSteps-2" ){
  
          var $inputs = $("#formSteps-2 :input:not(:submit)");
          var value = true;
  
          $inputs.each(function() {
              if( $(this).val().length &lt; 1 || $(this).hasClass("error")){
                  value = false;
              }
          });
          return value;   
      }
      ...
  
      ...
      else{
          alert("something is wrong");                
      }           
      return true;
  }   
  </code></pre>
  
  <p>Now I have four if that are the same just change the paramater <code>"mod_formStepsN"</code> and <code>"#formSteps-1"</code>.</p>