Regex Help

Discussion in 'Programming' started by rizzy, Mar 30, 2008.

  1. #1
    I am tying to create a regular expression to validate the following situation.

    The user will be entering dates in so it could be:
    YYYY or YYYY,YYYY,YYYY,...

    If the person is entering multiple dates I want each one to be unique. If anyone can help me out with this I would appreciate it.

    I have been trying to figure it out but all I can do is get it to match is the simplest one YYYY.
     
    rizzy, Mar 30, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, let's assume $x is your simplest one for just matching YYYY. You could easily make it allow more than one separated by commas afterwards.

    ($x(,)?)+


    Then if you want to make sure they're all different.. well, my suggestion would be to split/explode your match at commas and then compare each one to the others, or find a function that'll make an array unique.
     
    zerxer, Mar 31, 2008 IP