Link to home
Start Free TrialLog in
Avatar of 1jaws
1jawsFlag for United States of America

asked on

regex question

parsing "(19|20)\d\d/[1-9]|1[012])/([1-9]|[12][0-9]|3[01]" - Too many )'s.

I am trying to do date of birth textbox validate to see if they enter correct date.. it is
yyyy/mm/dd format ...getting this error above..
Avatar of ozo
ozo
Flag of United States of America image

where is the ( that matches the ) after 1[012]?
perhaps you meant
"(19|20)\d\d/([1-9]|1[012])/([1-9]|[12][0-9]|3[01])"
Avatar of 1jaws

ASKER

ok it fixed the error but what I am trying to accomplish is not.. I have for ex 1948/01/07 it is saying not correct format... can you please help on the regex how to do tha...
Your regex is only accepting that date in the form 1948/1/7
Do you want the leading 0 to be optional or required?
Avatar of 1jaws

ASKER

since I want that in yyyy/mm/dd it should be required...or I guess we can make optional so user wont have to figure it out.. what do youthink?
Avatar of 1jaws

ASKER

can we also add year 2000 to it is only accepting 19.. numbers now..
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
remove the ? to make the 0 required
Avatar of 1jaws

ASKER

can we also add year 2000 to it is only accepting 19.. numbers now..
(19|20) should accept either 19.. or 20..
Avatar of shadow77
shadow77

You may want to rearrange the day part of the expression as follows:
    (19|20)\d\d/(0?[1-9]|1[012])/(3[01]|[12][0-9]|0?[1-9])

The pattern above seems to match only "1948/5/1" when the test string is "1948/5/12".
>>>> parsing  "(19|20)\d\d/[1-9]|1[012])/([1-9]|[12][0-9]|3[01]" - Too  many )'s.

do like this:

((19|20)\d\d)/([1-9]|1[012])/([1-9]|[12][0-9]|3[01])

You had extra ')' 's in your expression so you were getting parsing error.
Avatar of 1jaws

ASKER

thanks sorry for the delayed response!!