title: Regular expression to check string is integer
body: <p>An HTML form returns me a string of a number entered by a user. How do I use regular expressions to see if it is capable of being a number or not. I do not simply want to strip away commas and see if it can be cast to int, nor do I like the locale.atoi method as the strings will evalaute to numbers even if they are nonsense (e.g. <code>locale.atoi('01,0,0'</code>) evaluates to 100).</p>
  
  <p>NB this validation only occurs if the string contains commas</p>
  
  <p>The re pattern should be:</p>
  
  <p>1st character is 1-9 (not zero)
  2nd and 3rd characters are 0-9
  Then 3 digits 1-9 and a comma repeated between 0 and 2 times (999,999,999,999 is largest number possible in the program)
  Then finally 3 digits 1-9</p>
  
  <pre><code>compiled = re.compile("[1-9][0-9]{0,2},(\d\d\d,){0,2}[0-9]{3}")
  </code></pre>
  
  <p>which is not matching the end of the string correctly, for example:</p>
  
  <pre><code>re.match(compiled, '123,456,78') 
  </code></pre>
  
  <p>is matching. What have I done wrong?</p>