title: RegEx for fixed number of digits?
body: <p>I'm finishing a form I have to do for my homework, and just when I thought I was finished, I found a mistake.</p>
  
  <p>I need a RegEx for input field that would return an alert if there's not exactly 13 digits.</p>
  
  <p>While I know the correct RegExp for this is: <code>/^\d{13}$/</code>, I also need it to ignore an empty field. (Because I don't want the alert to trigger in case the user switches to a different input field)</p>
  
  <p>Just when I thought I had it with: <code>/^$|\d{13}$/</code>, it turns out that it will return an alert if there are less than 13 digits but not if there are more, unlike <code>/^\d{13}$/</code> that is working fine with 14+ digits.</p>
  
  <p>Can someone help me out with this? Thanks</p>
  
  <p>Here's the rest of the function:</p>
  
  <pre><code>        function checkNum(box) {
          var re= new RegExp(/^$|\d{13}$/);
          if(!box.value.match(re)) {
              alert("13 numbers are required");
              document.getElementById("numbers").value = '';
          }
      }
  </code></pre>
  
  <p>And here is the input field:</p>
  
  <pre><code>&lt;input type="text" name="numbers" id="numbers" placeholder="Numbers" onFocus="this.placeholder=''" onBlur="checkNum(this); this.placeholder='Numbers'"/&gt;
  </code></pre>