473,657 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

date in format "dd/MM/yyyy" validation

Hi,

I program in asp.net. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is realy correct.

I used RegularExpressi onValidator with
ValidationExpre ssion="[0-3][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9]", but user
can write date "31/02/2000" and validator says that it is correct (everybody
know that Febuary has 28 or 29 days).

I was thinking of using RangeValidator with Type="Date". But how to told
RangeValidator, that date is in format "dd/MM/yyyy" ?

Maybe it is easier solution ?
I would like to have total secure validation method in client site..

Thanks for help

Nov 11 '08 #1
14 15310
<am*******@pocz ta.onet.plwrote in message
news:gf******** **@news.onet.pl ...
I program in ASP.NET. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is really correct.
Firstly, your date format is ambiguous. E.g. in that format, tomorrow's date
would appear as 12/11/2008. Some people will see that as 12 November but
others (e.g. our friends in US) will see it as 11 December 2008. You should
always display dates using a three-digit month.
Maybe it is easier solution ?
I would like to have total secure validation method in client site..
By far the easiest solution, and one which will never permit invalid dates,
is not to allow users to enter dates manually at all. Instead, use a date
picker.

There are dozens, maybe hundreds, of these available:
http://www.google.co.uk/search?hl=en...icker%22&meta=
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 11 '08 #2

"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:%2******** **********@TK2M SFTNGP05.phx.gb l...
<am*******@pocz ta.onet.plwrote in message
news:gf******** **@news.onet.pl ...
>I program in ASP.NET. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is really correct.

Firstly, your date format is ambiguous. E.g. in that format, tomorrow's
date would appear as 12/11/2008. Some people will see that as 12 November
but others (e.g. our friends in US) will see it as 11 December 2008. You
should always display dates using a three-digit month.
[...]
But I know that my date is in format "dd/MM/yyyy". I did:

<asp:TextBox ID="txtDateFrom " runat="server"> </asp:TextBox>
<cc1:CalendarEx tender ID="CalendarDat eFrom" runat="server"
TargetControlID ="txtDateFro m"
Format="dd/MM/yyyy">
Nov 11 '08 #3
"imbirek8" <im******@op.pl wrote in message
news:gf******** **@news.onet.pl ...
>>I program in ASP.NET. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is really correct.

Firstly, your date format is ambiguous. E.g. in that format, tomorrow's
date would appear as 12/11/2008. Some people will see that as 12 November
but others (e.g. our friends in US) will see it as 11 December 2008. You
should always display dates using a three-digit month.

[...]
But I know that my date is in format "dd/MM/yyyy".
Are you the only user of the system...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 11 '08 #4
Mark Rae [MVP] wrote:
"imbirek8" <im******@op.pl wrote in message
news:gf******** **@news.onet.pl ...
>>>I program in ASP.NET. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is really correct.

Firstly, your date format is ambiguous. E.g. in that format,
tomorrow's date would appear as 12/11/2008. Some people will see that
as 12 November but others (e.g. our friends in US) will see it as 11
December 2008. You should always display dates using a three-digit
month.

[...]
But I know that my date is in format "dd/MM/yyyy".

Are you the only user of the system...?
The trick of writing on the form in what format the date is to
be entered has been seen both on paper and on computers.

:-)

Arne
Nov 11 '08 #5
<am*******@pocz ta.onet.plwrote in message
news:gf******** **@news.onet.pl ...
I program in asp.net. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is realy correct.

I used RegularExpressi onValidator with
ValidationExpre ssion="[0-3][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9]", but
user can write date "31/02/2000" and validator says that it is correct
(everybody know that Febuary has 28 or 29 days).

I was thinking of using RangeValidator with Type="Date". But how to told
RangeValidator, that date is in format "dd/MM/yyyy" ?

Maybe it is easier solution ?
I would like to have total secure validation method in client site..
You can use a CustomValidator , and write your own validation code in a
small routine in javascript. You will also want to replicate that code in C#
on the server side, to cover the case where the user bypasses validation on
the client side.

Nov 11 '08 #6
With a Textbox

Try DateTime.TryPar se()
if its a good date returns true
example below

string sDate ="02/29/2007";

DateTime DateValue;

Console.WriteLi ne(DateTime.Try Parse(sDate,out DateValue).ToSt ring());

DaveL


<am*******@pocz ta.onet.plwrote in message
news:gf******** **@news.onet.pl ...
Hi,

I program in asp.net. I have a date in TextBox in format "dd/MM/yyyy".
I would like to validate if the date is realy correct.

I used RegularExpressi onValidator with
ValidationExpre ssion="[0-3][0-9]/[0-1][0-9]/[1-2][0-9][0-9][0-9]", but
user can write date "31/02/2000" and validator says that it is correct
(everybody know that Febuary has 28 or 29 days).

I was thinking of using RangeValidator with Type="Date". But how to told
RangeValidator, that date is in format "dd/MM/yyyy" ?

Maybe it is easier solution ?
I would like to have total secure validation method in client site..

Thanks for help

Nov 11 '08 #7
"Mark Rae [MVP]" <ma**@markNOSPA Mrae.netwrote in message
news:e$******** ******@TK2MSFTN GP03.phx.gbl...
[...]
Are you the only user of the system...?
No, but I thought that if I user code like this:

<asp:TextBox ID="txtDateFrom " runat="server"> </asp:TextBox>
<cc1:CalendarEx tender ID="CalendarDat eFrom" runat="server"
TargetControlID ="txtDateFro m"
Format="dd/MM/yyyy">

it doesn't mather globalizations and localizations settings in browser, am I
right ?

Nov 11 '08 #8
"DaveL" <dv*****@sbcglo bal.netwrote in message
news:_F******** *********@flpi1 49.ffdc.sbc.com ...
[...]
Try DateTime.TryPar se()
if its a good date returns true
example below

string sDate ="02/29/2007";

DateTime DateValue;

Console.WriteLi ne(DateTime.Try Parse(sDate,out DateValue).ToSt ring());
[...]

I user date in format "dd/MM/yyyy" not in format "MM/dd/yyyy". This method
doesn't work with this format.

Nov 11 '08 #9
"imbirek8" <im******@op.pl wrote in message
news:gf******** **@news.onet.pl ...
>Are you the only user of the system...?

No, but I thought that if I use code like this:

<asp:TextBox ID="txtDateFrom " runat="server"> </asp:TextBox>
<cc1:CalendarEx tender ID="CalendarDat eFrom" runat="server"
TargetControlID ="txtDateFro m" Format="dd/MM/yyyy">

it doesn't mather globalizations and localizations settings in browser, am
I right ?
No you are not, though the fact that you are now using a calendar control is
a step in the right direction.

However, so long as you continue to use an ambiguous date format, your app
will always be open to ambiguity...

The fact that *you* know what date format you're using is completely
irrelevant - you can't expect your users to be telepathic...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 11 '08 #10

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

Similar topics

6
2495
by: Erik R.N. | last post by:
Hi I have a ACCESS2002 table with a date-field in format "dd-mm-yyyy" which I "export" to a txt-file ( ; and " " ) and upload the txt-file to a MYSQL-table where the datefield is a varchar-field. I want to sort on the MYSQL-date-field. How do I get a MYSQL-date-formated "yyyy-mm-dd" field which I can sort on ??
2
2182
by: Ian | last post by:
I would like to have some validation on a date field. The date format is dd/mm which is used for our financial year end. I suppose I need also consider leap years. Please can you shed some light on how I will be able to achieve this?
6
3429
by: Sabina | last post by:
Hello, How can I porting this code to_date('" & Format(Date, "MM/DD/YYYY") & "','mm/dd/yyyy') from VB to aspx? SelectCommand="SELECT * FROM tbl_Products WHERE tbl_Products.ProductStartDate <= to_date('" & Format(Date, "MM/DD/YYYY") & "','mm/dd/yyyy')"
1
1601
by: kaw480 | last post by:
I was wondering if there was a way to show when a page was updated, and have that date displayed on a page.
5
4201
mgpsivan
by: mgpsivan | last post by:
Hi, i have form in Asp.net(2003) in that i've to change the format of the date by the following statement Format(Date.Today, "dd/mm/yyyy") but when i give this code the month part displays as 00 i.e i get the output as the folowing for eg: "18/00/2007" can any one help me in changing the format... Thanks in Advance..... Sivan.G.....
1
2784
by: nudrat | last post by:
I have a form in ASP, where Date has to display in "dd/mm/yyyy" format. when I am saving that format into database its giving either error message or saving incorrect date. because sql used to insert dates in "dd/mm/yyyy" format. say if date is 24 sep 2007, in sql it will not save as "24/09/2007", it will be out of script range error and if date is 3 sep 2007 , then sql will treat as 9 March 2007. please find a solution for that. Thanks &...
2
4720
by: stainless | last post by:
I know this is probably simple but I cannot find a method of converting a date string into a format that matches the DatePicker format in C# eg string "20080131" converted to "31 January 2008" I tried datetime.parseexact but could not find the definition for the appropriate format string. This would be a very useful tool fo me. Any ideas,please?
3
30801
by: maminx | last post by:
Hello all, asking again i want to convert format date from "YYYY-mm-dd" to "dd-mm-YYYY" example from "2008-08-16" become format date like this one "16-08-2008" is it anyone who has this library??thanks
1
9754
by: JFKJr | last post by:
Hello everyone, this one might be simple but driving me crazy! Your help will be greatly appreciated. Basically, I created a textbox bound to "Date" field in an Access VBA form. But when the field has date in "mm/dd/yyyy" format (for ex: 09/03/2008), the textbox displays it as 9/3/2008. Can anyone suggest how to display date in "mm/dd/yyyy" format in a bounded textbox. Thanks!
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8845
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
8743
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...
1
8522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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
5647
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
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
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
1736
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.