find if the date containd a valid format using a preg_match
<p>I have 1 text input box so user can enter a date in the following format (i don’t want to use 3 separate input boxes for the month, date and year) :</p>

<pre><code>mm/dd/yyyy (could be a single digit m/d/yyyy)
</code></pre>

<p>or</p>

<pre><code>mm-dd-yyyy (single digit m-d-yyyy)
</code></pre>

<p>I then want to use preg_match to check if the user entered a value according to the format above. If yes, i will extract the month, day and year (using substr) and use php function checkdate() to check for a valid date, know when it’s a leap year and prevent mistakes such as September 31...</p>

<p>Hopefully, i’m not missing anything...</p>

<p>Right now, im stuck in trying to figure out how to use preg_match to check if the user has entered a valid date according to the format indicated above</p>

<p>this is what i’ve came up with... ???</p>

<pre><code>preg_match(d{2})(\d{2})(\d{4})
</code></pre>

<p>extracting the month , day and year (looks ok to me):</p>

<pre><code>$date = trim($_POST['date']);
$month = substr($date, 0, 2);
$day = substr($date, 3, 2);
$year = substr($date, 6, 4);
</code></pre>

<p>and finally , check the date is valid (looks ok to me):</p>

<pre><code>checkdate($month, $day, $year);
</code></pre>

<p>Thanks</p>
