regex question

1jaws
1jaws used Ask the Experts™
on
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..
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
where is the ( that matches the ) after 1[012]?
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
perhaps you meant
"(19|20)\d\d/([1-9]|1[012])/([1-9]|[12][0-9]|3[01])"

Author

Commented:
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...
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Your regex is only accepting that date in the form 1948/1/7
Do you want the leading 0 to be optional or required?

Author

Commented:
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?

Author

Commented:
can we also add year 2000 to it is only accepting 19.. numbers now..
Most Valuable Expert 2014
Top Expert 2015
Commented:
"(19|20)\d\d/(0?[1-9]|1[012])/(0?[1-9]|[12][0-9]|3[01])"
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
remove the ? to make the 0 required

Author

Commented:
can we also add year 2000 to it is only accepting 19.. numbers now..
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
(19|20) should accept either 19.. or 20..

Commented:
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".
Shahan AyyubSenior Software Engineer

Commented:
>>>> 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.

Author

Commented:
thanks sorry for the delayed response!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial