title: Returning true or false from javascript function
body: <p>I'm doing a regex check on a string within a function:</p>
  
  <pre><code>function ValidateZipCodeString(listOfZipCodes) {
      var regex = /^([, ]*\d{5})+[, ]*$/,
      matches = regex.exec(listOfZipCodes);
  
      if (regex.exec(listOfZipCodes) === null) {
          console.log('validation failed');
          return false;
      } else {
          console.log('validation passed');
          return true;
      }
  }
  </code></pre>
  
  <p>The regex is correctly detecting a valid/invalid list of zip codes.</p>
  
  <p>I'm calling the function with this:</p>
  
  <pre><code>console.log('zip code: ' + listOfZipCodes);
  if (ValidateZipCodeString(listOfZipCodes)) {
      $tr.find('label#lblCoverageEditError').text('There is invalid text in the list of zip codes. Only 5-digit zip codes allowed.').show();
  } else {
      console.log('validate function returned true');
  }
  </code></pre>
  
  <p>The problem is that the above if/else goes to the else clause, when the console output within the validation function shows "validation failed". So I must not be calling that function right.</p>
  
  <p>What's the correct way to do what I'm trying to do?</p>