Help with regex

Discussion in 'PHP' started by ladieballer2004, Aug 26, 2009.

  1. #1
    I have a preg_match and it is supposed to flag if my date isn't in MM-YYYY format. Here is my code
    
    if 
      (!empty($_POST['StartDate'][$row]) && !preg_match('/^(0[1-9]|1[0-2]) [-] (19|20)\d{2}$/',$_POST['Startdate'][$row]))
      {echo '<b>One of your Start Date columns is not in the proper format. Make Sure it is MM-YYYY<br/>';$dataOK=FALSE;}
    
    Code (markup):
    what did i do wrong? Please Help
     
    ladieballer2004, Aug 26, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    (!empty($_POST['StartDate'][$row]) && !preg_match('/^(0[1-9]|1[0-2])\s*\-\s*(19|20)\d{2}$/',$_POST['Startdate'][$row]))
     
    premiumscripts, Aug 26, 2009 IP
  3. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Alternatively you could do (make sure date is not empty)

    $rowtime = strtotime($_POST['StartDate'][$row]);
    $newstr = date("m-d-Y", $rowtime);
     
    kblessinggr, Aug 26, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah, I'd suggest that, but I wasn't sure if strtotime works with an mm-yyyy format (without day).
     
    premiumscripts, Aug 26, 2009 IP