title: Regex: Separate validation of different string parts not working
body: <p>I am trying to check whether an input meets a given format - using Regex. </p>
  
  <ul>
  <li>Characters 1 to 4 of the input need to be digits (0-9). </li>
  <li>Character 5 needs to be a dash (-).</li>
  <li>Characters 6 to 8 also need to be digits (0-9).</li>
  </ul>
  
  <p><strong>Example:</strong><br>
  1234-567 should be ok. </p>
  
  <p>I have tried the following but I am a beginner regarding Regex and could not get this to work. </p>
  
  <p>Can someone help me with this and also provide some explanations around it so that I can apply it correctly next time ? </p>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>var str = '1234-567';
  var allowedChars1 = /^(.{3})[0-9]/;
  var allowedChars2 = /^.{4}(.{1})[\-]/;
  var allowedChars3 = /^.{5}(.{3})[0-9]/;
  
  if( (str.match(allowedChars1)) &amp;&amp; (str.match(allowedChars2)) &amp;&amp; (str.match(allowedChars3)) ) {
      console.log('ok');
  } else {
      console.log('error');
  }
  </code></pre>
  
  <p>Many thanks in advance, 
  Tom</p>