regular expression for DD/MM/YYYY in php is?

Discussion in 'PHP' started by spy100, Dec 30, 2009.

  1. #1
    I have a little problem...
    what's the regular expression for DD/MM/YYYY in PHP?
    I know that for MM/DD/YYYY is /^\d{1,2}\/\d{1,2}\/\d{4}$/
    but for DD/MM/YYYY what is it?
    I tried to google it but bad luck nothing?
    Pls help me!!! Thank you!!!
     
    spy100, Dec 30, 2009 IP
  2. ibg

    ibg Member

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #2
    It's the same :) /^\d{1,2}\/\d{1,2} means 2 consecutive numbers.
     
    ibg, Dec 31, 2009 IP
  3. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Colbyt, Dec 31, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you wanted a more accurate regex you could use
    '%^(0[1-9]|1[012])/(0[1-9]|[12][012]|3[01])/\d{4}$%'
    PHP:
    It will check that MM is 01 > 12
    DD is 01 > 31
    and that YYYY is four digits
    It's not perfect by a long way, but its better than just \d{2} which can have anything from 00 > 99
     
    JAY6390, Dec 31, 2009 IP