Help on Regular experession to validate date

B

Bogdan Zamfir

Hi,

I want to use RegularExpressionValidator to validate a date

I want to let user to enter date in the following format

one or two digits for day
one or two digits for month
two or four digits for year
User should be allowed to use as date Separator either . or - or /

So this should be valid date

1/11/03
21.5.2004
3-11-00

If I use the following regular expression it allows only . as date separator
\d{1,2}\.\d{1,2}\.(\d{2}|\d{4})
I tryed the following sequence for separator, to allow any of the three I
mention above, but it doesn't works.
(\.|\-|\/)
I tried with the following one too
(.|-|/)
None of them are working

Can anyone tell me what I did wrong?

Thank you.
Bogdan
 
H

Hans Kesting

Bogdan Zamfir said:
Hi,

I want to use RegularExpressionValidator to validate a date

I want to let user to enter date in the following format

one or two digits for day
one or two digits for month
two or four digits for year
User should be allowed to use as date Separator either . or - or /

So this should be valid date

1/11/03
21.5.2004
3-11-00

If I use the following regular expression it allows only . as date separator
\d{1,2}\.\d{1,2}\.(\d{2}|\d{4})
I tryed the following sequence for separator, to allow any of the three I
mention above, but it doesn't works.
(\.|\-|\/)
I tried with the following one too
(.|-|/)
None of them are working

Can anyone tell me what I did wrong?

Thank you.
Bogdan

try this
\d{1,2}[-./]\d{1,2}[-./](\d{2}|\d{4})

the "[-./]" part matches one of "-" , '." or "/". Take care: within [] the -
is also a special
character to signal a range.( [a-z] is "lowercase letter between a and z").
Only as first
or last character it is recognised as a "minus".

Hans Kesting
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top