By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,705 Members | 1,301 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,705 IT Pros & Developers. It's quick & easy.

Regular Expression Question

P: n/a
I hope this is an appropriate group for this question - if not, let me know
where I should take this question.

I want a regular expression that will validate a date in the format
mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900 and
1/1/1960 but I cannot get past the basic validation of the date. I am using
the validator at
http://www.web1marketing.com/resourc...ion-tester.php
and when I enter data such as "6/" it fails The regex fragment I am using is
"(0?[1-9]|1[012])[- /.]". The problem is in the [- /.] clause. In searching
the web, this looks as if it should work. What am I missing?

Wayne
Mar 9 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
If all you want to do is verify that the date is between two dates is
to use the CompareTo function of DateTime class.

heres a link to the docs:

http://msdn.microsoft.com/library/de...aretotopic.asp

when you use compareto it returns less than zero, zero or greater than
zero to show if the date is before, equal to or after the specified
date. No need to use a regex here

Mar 9 '06 #2

P: n/a
> The problem is in the [- /.] clause. In searching

If I understand, you want to match one of the following characters -, /,
.. as date delimiters. You need to escape at least the "." because "." is
used in regex as "any character". It works with [\- \/\.]
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Mar 9 '06 #3

P: n/a
Thank you. I'll give that a try.

Wayne

"dkode" <dk****@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
If all you want to do is verify that the date is between two dates is
to use the CompareTo function of DateTime class.

heres a link to the docs:

http://msdn.microsoft.com/library/de...aretotopic.asp

when you use compareto it returns less than zero, zero or greater than
zero to show if the date is before, equal to or after the specified
date. No need to use a regex here

Mar 9 '06 #4

P: n/a
Thank you

"Peter Macej" <pe***@vbdocman.com> wrote in message
news:e5**************@TK2MSFTNGP14.phx.gbl...
The problem is in the [- /.] clause. In searching


If I understand, you want to match one of the following characters -, /, .
as date delimiters. You need to escape at least the "." because "." is
used in regex as "any character". It works with [\- \/\.]
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB .NET
and ASP .NET code

Mar 9 '06 #5

P: n/a
"Wayne Wengert" <wa***********@wengert.org> schrieb:
I hope this is an appropriate group for this question - if not, let me know
where I should take this question.

I want a regular expression that will validate a date in the format
mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900
and 1/1/1960 but I cannot get past the basic validation of the date.


You could use 'Date.Parse'/'Date.ParseExact' for this purpose. If the date
can be parsed, you can compare the resulting 'Date' object to the two
bounds.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 9 '06 #6

P: n/a
Thanks for the response. I am going to try the CompareTo method suggested
earlier. I'll see if I can make that work.

Wayne

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ut**************@TK2MSFTNGP12.phx.gbl...
"Wayne Wengert" <wa***********@wengert.org> schrieb:
I hope this is an appropriate group for this question - if not, let me
know where I should take this question.

I want a regular expression that will validate a date in the format
mm/dd/yyyy. I actually want to verify that the date is between 1/1/1900
and 1/1/1960 but I cannot get past the basic validation of the date.


You could use 'Date.Parse'/'Date.ParseExact' for this purpose. If the
date can be parsed, you can compare the resulting 'Date' object to the two
bounds.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.