Date Validation

  • Thread starter Thread starter Diego
  • Start date Start date
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.
 
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.
 
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.
 
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
 
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.
 
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
 
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
 

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

Back
Top