date in format "dd/MM/yyyy" validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Mark Rae said:
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.[/QUOTE]

[...]
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">
 
Mark said:
imbirek8 said:
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
 
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.
 
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
 
[...]
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 ?
 
[...]
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.
 
Mark Rae said:
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 said:
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
 
Back
Top