Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
There should be a space between date and time.
Thanks,
Miguel 5 13798
"shapper" <md*****@gmail.comwrote in message
news:c9**********************************@c58g2000 hsc.googlegroups.com...
Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
There should be a space between date and time.
Thanks,
Miguel
\d\d-\d\d-\d{4} \d\d:\d\d:\d\d
Matches for me....although I would probably use the DateTime.TryParse method
instead so you don't have to limit the input to a single format.
HTH,
Mythran
On Jun 19, 2:38*am, shapper <mdmo...@gmail.comwrote:
Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
There should be a space between date and time.
Thanks,
Miguel
Instead of RegEx, Try using DateTime.TryParse, that should be the
better approach.
-Cnu
shapper wrote:
Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
There should be a space between date and time.
Thanks,
Miguel
If you use a regular expression, you can only validate the format of the
date, you can not validate that it's actually a valid date.
For example, a simple regular expression would allow a date like
"42-18-2008 29:63:81". A more advanced regular expression could catch
that, but it can still not tell that "29-02-2007 10:32:45" is not a
valid date.
Use the DateTime.TryParseExact method with a format like
"dd'-'MM'-'yyyy' 'HH':'mm':'ss" to validate the string.
--
Göran Andersson
_____ http://www.guffa.com
On Jun 19, 9:47*am, Göran Andersson <gu...@guffa.comwrote:
shapper wrote:
Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
There should be a space between date and time.
Thanks,
Miguel
If you use a regular expression, you can only validate the format of the
date, you can not validate that it's actually a valid date.
For example, a simple regular expression would allow a date like
"42-18-2008 29:63:81". A more advanced regular expression could catch
that, but it can still not tell that "29-02-2007 10:32:45" is not a
valid date.
Use the DateTime.TryParseExact method with a format like
"dd'-'MM'-'yyyy' 'HH':'mm':'ss" to validate the string.
--
Göran Andersson
_____http://www.guffa.com
Hi,
I was able to do it using:
^([0-9]{4})-([0-1][0-9])-([0-3][0-9])\s([0-1][0-9]|[2][0-3]):([0-5]
[0-9]):([0-5][0-9])$
But this does no accept empty values.
Can I create a RegEx that accepts empty values and when the value is
not empty then it validates?
Thanks,
Miguel
shapper wrote:
On Jun 19, 9:47 am, Göran Andersson <gu...@guffa.comwrote:
>shapper wrote:
>>Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45 There should be a space between date and time. Thanks, Miguel
If you use a regular expression, you can only validate the format of the date, you can not validate that it's actually a valid date.
For example, a simple regular expression would allow a date like "42-18-2008 29:63:81". A more advanced regular expression could catch that, but it can still not tell that "29-02-2007 10:32:45" is not a valid date.
Use the DateTime.TryParseExact method with a format like "dd'-'MM'-'yyyy' 'HH':'mm':'ss" to validate the string.
-- Göran Andersson _____http://www.guffa.com
Hi,
I was able to do it using:
^([0-9]{4})-([0-1][0-9])-([0-3][0-9])\s([0-1][0-9]|[2][0-3]):([0-5]
[0-9]):([0-5][0-9])$
That would accept a date like 2008-19-39...
This will get you a bit closer:
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])\s([0-1]\d|2[0-3])(:[0-5]\d){2}$
But still it has no idea about the different number of days in months. A
date like 2008-02-31 is still accepted.
But this does no accept empty values.
Can I create a RegEx that accepts empty values and when the value is
not empty then it validates?
You can just add ()? around the expression to make it conditional:
^(\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])\s([0-1]\d|2[0-3])(:[0-5]\d){2})?$
--
Göran Andersson
_____ http://www.guffa.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J. J. Cale |
last post by:
Little astrology program has 2 text input boxes for birth dates. There are 3
selects for day month year that will supply output to whichever text input
had the focus last. If the user picks from...
|
by: Colin Reid |
last post by:
Hey MS, here's an apparent problem in the base class library. I pulled
the email validation pattern
"^((*)*@(()+(*)*\.)+{2,9})"
from http://regexlib.com.
If I validate the email address...
|
by: Tim Conner |
last post by:
Hi,
Thanks to Peter, Chris and Steven who answered my previous answer about
regex to split a string. Actually, it was as easy as create a regex with the
pattern "/*-+()," and most of my string...
|
by: rjb |
last post by:
Hi!
Could somebody have a look and help me to optimize the code below.
It may look like very bad way of coding, but this stuff is very, very new
for me.
I've included just few lines.
Regex...
|
by: |
last post by:
Here is an interesting one. Running asp.net 2.0 beta 2. I have a regular
expression used in a regex validator that works on the client side in
Firefox but not in IE. Any ideas? IE always reports...
|
by: Steve |
last post by:
Hi All,
I'm having a tough time converting the following regex.compile patterns
into the new re.compile format. There is also a differences in the
regsub.sub() vs. re.sub()
Could anyone lend...
|
by: ad |
last post by:
I am useing VS2005 to develop wep application.
I use a RegularExpress both in RegularExpressionValidator and Regex class to
validate a value.
The RegularExpress is 20|\-9|\-1|?\d{1}
When I...
|
by: Phil Barber |
last post by:
I am using Regex to validate a file name. I have everything I need except I
would like the dot(.) in the filename only to appear once. My question is it
possible to allow one instance of character...
|
by: |
last post by:
Hi all,
Sorry for the lengthy post but as I learned I should post
concise-and-complete code.
So the code belows shows that the execution of ValidateAddress consumes a
lot of time. In the test...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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...
| |