473,785 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1489
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.c om> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.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******** ******@TK2MSFTN GP14.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.ParseExac t' 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******** ******@TK2MSFTN GP12.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.ParseExac t' 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
9746
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) method/function, I need the second argument 'replacement' to be another regular expression ( not a string) . So when I find a 'certain kind of string' in
5
2534
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, and then reconstruct another URL based on it. For example, I need to scan a web page looking for something like <a href="some_dir/list_20050815100225.csv">. I don't know in advance what the date/time in the file name will be. I need to take the...
10
3037
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 other words, as the regular expression (....)($) matches the "4567" in the string "1234567", how would I create a similar regular expression that only matches the "45" in the same string. The same regular expression would match "32" in the string...
18
3043
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
3110
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 and this method does not.... Does anyone have an explanation? Function IsValidEmail(ByVal strIn As String) As Boolean
7
371
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 - Album- i have try this syntax but it failed
7
3830
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
6
2293
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 work: it seems that < is not a valid character, so the beginning of the word starts at theletter 'p' instead of '<'. Because I'm not an expert in regular expressions, maybe someone of you guys can help me? I need the correct regex to find the...
3
2566
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 expression. ^(.+?) uses (?!a spoon)\.$
25
5169
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 (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.