Help on Regular experession to validate date

  • Thread starter Thread starter Bogdan Zamfir
  • Start date Start 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
 
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
 
Back
Top