title: Better way to implement a validator than a number of if statements
body: <p>I have a validator within my Angular app that is validating inputs of IP ranges to ensure the ranges are valid before they are submitted through a form. The validation itself all works fine but the general structure of the validator class leaves me wondering whether there is a better way to implement this.</p>
  
  <p>A switch won't work for this particular scenario, so that's out of the question. </p>
  
  <p>A simplified version of my validation method looks like this</p>
  
  <pre><code>validate(input: ipRange[]) { 
      for (let i = 0; i &lt; ipRanges.length; i++) {
          let range1 = ipRange.range1;
          let range2 = ipRange.range2;
  
          if(!validatorRule1(range1) &amp;&amp; !validatorRule1(range2) {
              //log ip range as invalid 
              continue;
          }
  
         if(!validatorRule2(range1) &amp;&amp; !validatorRule2(range2) {
              //log ip range as invalid 
              continue;
          }
  
          etc...
  
          // log range as valid
      }
  } 
  </code></pre>
  
  <p>This is fine for a small amount of rules, but the method gets longer with each new rule that needs to be added. It's readable, but it doesn't look the most professional. What would be the best way to refactor this functionality so that it looked better? </p>