Date Validation

D

Diego

Can I validate (possibly with a compare validator) a Date entered by the
user based upon his regional settings?
I.e. if a user is american the format would be mm/dd/yyyy, if brittish
dd/mm/yyyy
Thanks, Diego.
 
D

Diego

I tried but I'm in england with an english pc and when i try to use an
english date format (dd/mm/yyyy) the validation fails, the validation
succedes only with the american format (mm/dd/yyyy)
Any suggestions?
Thans, Diego.
 
D

Diego

Sorry I've replyed too quickly, Is it possible to do a validation depending
on the user culture? i.e. if an american logs in I accept 12/31/2005 and if
an English does I accept 31/12/2005?
Thanks, Diego.
 
T

Tom.PesterDELETETHISSS

I did some tests and the validation on the client reflects the culture that
was specified on the server.

A quick test is to add this to the page directive
<%@ Page Culture="en-US" %>
or
<%@ Page Culture="nl-BE" %>

The culture is now specified static and if you want to set it depending on
the browser user's culture you have to use these techniques :
for asp.net 1 http://west-wind.com/weblog/posts/334.aspx
for asp.net 2 its easier http://dotnetjunkies.com/WebLog/anoras/archive/2005/02/13/54271.aspx


Let me know if you have any more questions..

Cheers,
Tom Pester
 
D

Diego

Another question, once I've declared the culture in the page I try to do
something like this

obect.date = Convert.ToDateTime(grid["date"]) and I have an error (cannot
convert string to date), how can I convert the date according to the user
format?
Thanks, Diego.
 
T

Tom.PesterDELETETHISSS

What is the string that you try to convert there?

Don't forget about DateTime.Parse() too.

Cheers,
Tom Pester
Another question, once I've declared the culture in the page I try to
do something like this

obect.date = Convert.ToDateTime(grid["date"]) and I have an error
(cannot
convert string to date), how can I convert the date according to the
user
format?
Thanks, Diego.
I did some tests and the validation on the client reflects the
culture that was specified on the server.

A quick test is to add this to the page directive
<%@ Page Culture="en-US" %>
or
<%@ Page Culture="nl-BE" %>
The culture is now specified static and if you want to set it
depending on
the browser user's culture you have to use these techniques :
for asp.net 1 http://west-wind.com/weblog/posts/334.aspx
for asp.net 2 its easier
http://dotnetjunkies.com/WebLog/anoras/archive/2005/02/13/54271.aspx
Let me know if you have any more questions..

Cheers,
Tom Pester
 
T

Tom.PesterDELETETHISSS

This code works perfectly :

<%@ Page Language="C#" Culture="en-GB" %>

<%
DateTime r = new DateTime();
r = Convert.ToDateTime("25/01/2005");
Response.Write(r);

%>

Are you asking the wrong question?

Cheers,
Tom Pester
 
T

Tom.PesterDELETETHISSS

I am using asp.net 2.0 too and I still can't reproduce the problem.

Let me know if you have any more questions..

Cheers,
Tom Pester
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top