Regular Expression Question

W

Wayne Wengert

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/resources/tools/regular-expression-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
 
P

Peter Macej

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 [\- \/\.]
 
W

Wayne Wengert

Thank you

Peter Macej said:
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
 
H

Herfried K. Wagner [MVP]

Wayne Wengert said:
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.
 
W

Wayne Wengert

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

Wayne
 

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

Top