title: Regex matching a date and time
body: <p>I'm trying to match a specific datetime format in PHP's regex:</p>
  
  <pre><code>dd-mm-YYYY HH:ii:ss
  </code></pre>
  
  <p>It should always be in that format. Meaning that for example when it is the first day of the month there must be a leading zero. E.g.:</p>
  
  <pre><code>01-01-2013 01:01:01
  </code></pre>
  
  <p>I tried it with the following pattern:</p>
  
  <pre><code>^[0-12]{2}-[0-31]{2}-[0-9]{4} [0-23]{2}:[0-59]{2}:[0-59]{2}$
  </code></pre>
  
  <p>But the above pattern fails on timestamps like: <code>09-05-2013 19:45:10</code>.</p>
  
  <p><a href="http://rubular.com/r/eGBAhwiNCR" rel="nofollow">http://rubular.com/r/eGBAhwiNCR</a></p>
  
  <p>I understand this may not be the correct approach to validate a date time like this, but I really want to know what is wrong with the above.</p>