473,387 Members | 1,585 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,387 software developers and data experts.

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 RegularExpressionValidator with
ValidationExpression="[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 15259
<am*******@poczta.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**@markNOSPAMrae.netwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
<am*******@poczta.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:CalendarExtender ID="CalendarDateFrom" runat="server"
TargetControlID="txtDateFrom"
Format="dd/MM/yyyy">
Nov 11 '08 #3
"imbirek8" <im******@op.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".
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.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".

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*******@poczta.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 RegularExpressionValidator with
ValidationExpression="[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.TryParse()
if its a good date returns true
example below

string sDate ="02/29/2007";

DateTime DateValue;

Console.WriteLine(DateTime.TryParse(sDate,out DateValue).ToString());

DaveL


<am*******@poczta.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 RegularExpressionValidator with
ValidationExpression="[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**@markNOSPAMrae.netwrote in message
news:e$**************@TK2MSFTNGP03.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:CalendarExtender ID="CalendarDateFrom" runat="server"
TargetControlID="txtDateFrom"
Format="dd/MM/yyyy">

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

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

string sDate ="02/29/2007";

DateTime DateValue;

Console.WriteLine(DateTime.TryParse(sDate,out DateValue).ToString());
[...]

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.plwrote 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:CalendarExtender ID="CalendarDateFrom" runat="server"
TargetControlID="txtDateFrom" 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
"imbirek8" <im******@op.plwrote in message
news:gf**********@news.onet.pl...
I user date in format "dd/MM/yyyy" not in format "MM/dd/yyyy". This
method doesn't work with this format.
Now that you're using a calendar control, and users cannot enter dates
manually, you no longer need to do any date format validation - that's the
whole point of using a date picker...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 11 '08 #11
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote:
>
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.
Do you mean "three-character month"? That is, "12/Nov/2008"? I have
certainly never seen an interface that used a 3-digit month.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 13 '08 #12
"Tim Roberts" <ti**@probo.comwrote in message
news:mu********************************@4ax.com...
>>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.

Do you mean "three-character month"? That is, "12/Nov/2008"?
Yes. Apologies for usage of incorrect terminology.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 13 '08 #13
Tim Roberts wrote:
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote:
>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.

Do you mean "three-character month"? That is, "12/Nov/2008"? I have
certainly never seen an interface that used a 3-digit month.
It is used. As 12-Nov-2008 not 12/Nov/2008 though.

In contexts where readers can be both American and European it
is a good way to ensure that everybody reads it as the same
date.

Arne
Nov 15 '08 #14
Arne Vajhøj <ar**@vajhoej.dkwrote:
>Tim Roberts wrote:
>"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote:
>>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.

Do you mean "three-character month"? That is, "12/Nov/2008"? I have
certainly never seen an interface that used a 3-digit month.

It is used. As 12-Nov-2008 not 12/Nov/2008 though.
That's not a three-digit month. That's a three-character month, as I said.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 16 '08 #15

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

Similar topics

6
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....
2
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...
6
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 ...
1
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
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...
1
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...
2
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" ...
3
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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 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.