473,405 Members | 2,421 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,405 software developers and data experts.

Regular expression for date : DDMMMYYY

1
Hi,

I am using a regular expression to validate a date format. The Date format which the user would enter is : DDMMMYYYY ( like 10OCT2001)

I am using the following regular expression :

^(0[1-9]|[12][0-9]|3[01])(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC| jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)(1 9|20)\d\d$

But this fails, if the user gives a combination of upper and lower case in months
( something like 10Oct2009 )...so could you please tell me how to change the above regex so that it ignores the case in the month field ?
Oct 28 '09 #1
3 4566
tlhintoq
3,525 Expert 2GB
I'm not good at RegEx but I can make a suggestion...
Take the text entered by the user and fix it before you check it.

Expand|Select|Wrap|Line Numbers
  1. string usersubmission = Textbox1.Text.ToUpper();
  2. // Go check against RegEx
Oct 28 '09 #2
Plater
7,872 Expert 4TB
For this specific example, couldn't you use the DateTime object's ParseExact() or TryParseExact() functions? It takes in a parameter of like "DDMMMYYYY" as a pattern.

For example:
Expand|Select|Wrap|Line Numbers
  1.  
  2. DateTime myDT = DateTime.MinValue;
  3. IFormatProvider culture = System.Globalization.CultureInfo.CurrentCulture;
  4. bool result=DateTime.TryParseExact(myTextbox.Text, "DDMMMYYYY", culture, System.Globalization.DateTimeStyles.AssumeLocal, out myDT);
  5.  
  6.  
Oct 28 '09 #3
GaryTexmo
1,501 Expert 1GB
I did a bit of googling, you can set an option to have your RegEx ignore case. Here's the MSDN page on it...

http://msdn.microsoft.com/en-us/libr...exoptions.aspx

From that page...
Expand|Select|Wrap|Line Numbers
  1. Regex rxInsensitive = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
  2.  
Hopefully that helps! :)
Oct 28 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: GIMME | last post by:
For starters .... If : //input is the xpath syntax to see if an element with an attribute named start_date exists ... Then what is the xpath syntax to return elements having
6
by: paulsmith5 | last post by:
Hi, I have the following regular expression to validate a date-time field in European or d/m/y h:m:s format. ...
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,...
3
by: Danny | last post by:
I am trying to do a regular expression to search for a url so anything that has http:\\www.hellothere.com but may not have the http:\\ and may not have the www and may not have http:\\www and...
2
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I mean that the input string could not yet be...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
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...
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 -...
6
by: Wayne Wengert | last post by:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...
0
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...

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.