473,799 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on Regular experession to validate date

Hi,

I want to use RegularExpressi onValidator to validate a date

I want to let user to enter date in the following format

one or two digits for day
one or two digits for month
two or four digits for year
User should be allowed to use as date Separator either . or - or /

So this should be valid date

1/11/03
21.5.2004
3-11-00

If I use the following regular expression it allows only . as date separator
\d{1,2}\.\d{1,2 }\.(\d{2}|\d{4} )
I tryed the following sequence for separator, to allow any of the three I
mention above, but it doesn't works.
(\.|\-|\/)
I tried with the following one too
(.|-|/)
None of them are working

Can anyone tell me what I did wrong?

Thank you.
Bogdan


Nov 17 '05 #1
2 3292

"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:Oi******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I want to use RegularExpressi onValidator to validate a date

I want to let user to enter date in the following format

one or two digits for day
one or two digits for month
two or four digits for year
User should be allowed to use as date Separator either . or - or /

So this should be valid date

1/11/03
21.5.2004
3-11-00

If I use the following regular expression it allows only . as date separator \d{1,2}\.\d{1,2 }\.(\d{2}|\d{4} )
I tryed the following sequence for separator, to allow any of the three I
mention above, but it doesn't works.
(\.|\-|\/)
I tried with the following one too
(.|-|/)
None of them are working

Can anyone tell me what I did wrong?

Thank you.
Bogdan


try this
\d{1,2}[-./]\d{1,2}[-./](\d{2}|\d{4})

the "[-./]" part matches one of "-" , '." or "/". Take care: within [] the -
is also a special
character to signal a range.( [a-z] is "lowercase letter between a and z").
Only as first
or last character it is recognised as a "minus".

Hans Kesting

Nov 17 '05 #2

"Bogdan Zamfir" <ams_soft at pcnet dot ro> wrote in message
news:Oi******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I want to use RegularExpressi onValidator to validate a date

I want to let user to enter date in the following format

one or two digits for day
one or two digits for month
two or four digits for year
User should be allowed to use as date Separator either . or - or /

So this should be valid date

1/11/03
21.5.2004
3-11-00

If I use the following regular expression it allows only . as date separator \d{1,2}\.\d{1,2 }\.(\d{2}|\d{4} )
I tryed the following sequence for separator, to allow any of the three I
mention above, but it doesn't works.
(\.|\-|\/)
I tried with the following one too
(.|-|/)
None of them are working

Can anyone tell me what I did wrong?

Thank you.
Bogdan


try this
\d{1,2}[-./]\d{1,2}[-./](\d{2}|\d{4})

the "[-./]" part matches one of "-" , '." or "/". Take care: within [] the -
is also a special
character to signal a range.( [a-z] is "lowercase letter between a and z").
Only as first
or last character it is recognised as a "minus".

Hans Kesting

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1128
by: dcinfinite | last post by:
hi.. i have a few other questions 2 ask..i used the "calender" function to insert Date of Birth for my "add customer form" is that advisible?coz i feel it'll be easy for customers to just click on the date and month in the calender for thier DOB..but is this method appropriate since the Calender defalut displays the year starting from 2005? besides that, i'm using "regular expression validator" to validate the "email" field. the...
6
2036
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. ^((((31\/(0?|1))|((29|30)\/(0?|1)))\/(1|\d)?\d{2})|(29\/0?2\/(((1|\d)?(0||)|((16||)00))))|(0?|1\d|2)\/((0?)|(1))\/((1|\d)?\d{2})) (20|21|22|23|?\d):?\d:?\d$ I wish to ammend it so that the time or h:m:s part is validated only if supplied (i.e. I wish to make the time part optional). At present if a
2
7959
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 complete but I want to know if a match is possible so far. For instance I want to design a text box to enter a date and validate the correctness of the date as the user types character. If the user enters 1953/12/23 it will match my regex of course...
4
1918
by: Frank Rocco | last post by:
Hello, What is the best way to validate a textbox to see if it contains a valid date or a valid time or both? Thanks Frank
0
891
by: Bogdan Zamfir | last post by:
Hi, I want to use RegularExpressionValidator to validate a date I want to let user to enter date in the following format one or two digits for day one or two digits for month two or four digits for year User should be allowed to use as date Separator either . or - or /
18
3044
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 ??
22
4452
by: deepak.rathore | last post by:
can someone give the regular expr. to validate leap yr like 02/29/2000,02/29/00 Thanks
6
1491
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 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...
3
7234
by: samuelberthelot | last post by:
Hello, I would like to validate a date in a textbox on the onChange event. The date must be in the format 01/01/2007 I would like to use a regular expression to validate it but I'm not very familiar with them. How can I do it ? Thanks
0
9538
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
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...
1
7561
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
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
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
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
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.