title: Regex for digits and hyphen only
body: <p>I am trying to understand regex, for digits of length 10 I can simply do</p>
  
  <pre><code>/^[0-9]{10}$/
  </code></pre>
  
  <p>for hyphen only I can do</p>
  
  <pre><code>/^[-]$/
  </code></pre>
  
  <p>combining the two using group expression will result in</p>
  
  <pre><code>/^([0-9]{10})|([-])$/
  </code></pre>
  
  <p>This expression does not work as intended, it somehow will match part of the string instead of not match at all if the string is invalid.</p>
  
  <p><a href="https://i.stack.imgur.com/R3JCr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R3JCr.png" alt="enter image description here"></a></p>
  
  <p>How do I make the regex expression that accepts only "-" or 10 digits?</p>