title: Validating expiration date in php
body: <p>I am trying to validate credit card expiry date as entered by the user in PHP. This is what I have so far:</p>
  
  <pre><code>if (!isset($_POST["cardDate"])) {
          header("location:payment.php");
          exit();
      }
      else {
          $cardDate=$_POST["cardDate"];
  
          if ($cardDate=="") {
          $err_msg .="&lt;p&gt;Please enter the credit card expiration date.&lt;/p&gt;";
  
      }   
      else {
          if (!preg_match("/^(0[1-9]|1[0-2])[-][0-9]{2}$/", $cardDate)) {
             $err_msg .= "&lt;p&gt;The expire date format is not correct!&lt;/p&gt;";
  
          }
          else {
              $currentDate = date('m/y');
              $exp = strtotime($cardDate);
              $current = strtotime($currentDate);
              if ($current&gt;$exp) {
                  $err_msg .= "&lt;p&gt;Credit card has expired";
              }
          }
      }
      }
  </code></pre>
  
  <p>The code currently is not working and I think it is because the user will be entering the expiry date in the "mm-yy" format and I am not sure whether the $currentDate part of the code conveys that message. Does anyone have any suggestions as to what needs to be changed in order for PHP to validate the expiry date? An example of the input date would be 05/19 or 11/20. The code will then match whether 05/19 or 11/20 has already passed by comparing it to today's date which is 05/20. The card expiry date must be after the current date. 
  HTML code</p>
  
  <pre><code>&lt;p&gt;&lt;label for="cardDate"&gt;Credit card expiration date&lt;/label&gt;
  &lt;input type="text" name="cardDate" id="cardDate" maxlength="5" size="5" required="required" placeholder="mm-yy" /&gt;&lt;/p&gt;
  </code></pre>