By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

date in format "dd/MM/yyyy" validation

P: n/a
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
Share this Question
Share on Google+
14 Replies


P: n/a
<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

P: n/a

"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

P: n/a
"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

P: n/a
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

P: n/a
<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

P: n/a
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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.