473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Regular Expression Question

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
6 1463
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
> 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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
5
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.