title: Regex matching hyphen and comma and only in between
body: <p>I am checking for a string using regex.</p>
  
  <p><strong>The rule is :</strong></p>
  
  <p>The String can, </p>
  
  <p>contain any digits, hyphen and comma</p>
  
  <p>Hyphen and Comma should be only in-between the digits.  It should not in the beginning or the end of the string.</p>
  
  <p>Comma is optional.  Hyphen is compulsory</p>
  
  <p>For Example,</p>
  
  <p><strong>Valid :</strong></p>
  
  <pre><code>10-20
  10-20-3
  10-20,3 
  </code></pre>
  
  <p><strong>InValid :</strong></p>
  
  <pre><code>10
  -10
  ,10
  10-20,
  10-20-
  10,20
  </code></pre>
  
  <p><strong>The code I tried so far:</strong></p>
  
  <pre><code>[0-9,-]+ 
  </code></pre>
  
  <p><em>can someone suggest how to check the coma and hyphen should not be in the beginning or end of the string and also the above conditions?</em> </p>