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

Date Validation

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Hi Diego
DateTime.Parse is what you need :
http://msdn.microsoft.com/library/de...parsetopic.asp

I hope it helps...

Cheers,
Tom Pester
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

Nov 19 '05 #2

P: n/a
The CompareValidator works for this. Set its Operator=DataTypeCheck and
Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Diego" <t> wrote in message news:O2**************@tk2msftngp13.phx.gbl...
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.

Nov 19 '05 #3

P: n/a
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The CompareValidator works for this. Set its Operator=DataTypeCheck and
Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Nov 19 '05 #4

P: n/a
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.
"Diego" <t> wrote in message news:Ok**************@tk2msftngp13.phx.gbl...
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The CompareValidator works for this. Set its Operator=DataTypeCheck and
Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx


Nov 19 '05 #5

P: n/a
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/anor.../13/54271.aspx
Let me know if you have any more questions..

Cheers,
Tom Pester
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.
"Diego" <t> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The CompareValidator works for this. Set its Operator=DataTypeCheck
and Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

Nov 19 '05 #6

P: n/a
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.
<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
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/anor.../13/54271.aspx

Let me know if you have any more questions..

Cheers,
Tom Pester
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.
"Diego" <t> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The CompareValidator works for this. Set its Operator=DataTypeCheck
and Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx


Nov 19 '05 #7

P: n/a
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.
<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
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/anor.../13/54271.aspx
Let me know if you have any more questions..

Cheers,
Tom Pester
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.
"Diego" <t> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
> The CompareValidator works for this. Set its
> Operator=DataTypeCheck and Type=Date.
>
> For an article on common answers to validation problems, see
> http://aspalliance.com/699.
>
> --- Peter Blum
> www.PeterBlum.com
> Email: PL****@PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.asp

Nov 19 '05 #8

P: n/a
The string is 25/01/2005 (english format)
Thanks, Diego.
Nov 19 '05 #9

P: n/a
Hi Diego,

Please read the article I provided (http://aspalliance.com/699) because it
tells you exactly how to setup the culture for validators. See the heading
"Validators support for globalization".

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Diego" <t> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
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.
"Diego" <t> wrote in message news:Ok**************@tk2msftngp13.phx.gbl...
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.
"Peter Blum" <PL****@Blum.info> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The CompareValidator works for this. Set its Operator=DataTypeCheck and
Type=Date.

For an article on common answers to validation problems, see
http://aspalliance.com/699.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx



Nov 19 '05 #10

P: n/a
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
The string is 25/01/2005 (english format)
Thanks, Diego.

Nov 19 '05 #11

P: n/a
I forgot to mention that I'm using asp.net 2.0, and the code doesen't work.
Diego.

<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
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
The string is 25/01/2005 (english format)
Thanks, Diego.


Nov 19 '05 #12

P: n/a

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
I forgot to mention that I'm using asp.net 2.0, and the code doesen't
work. Diego.

<To********************@pandora.be> wrote in message
news:a1**************************@news.microsoft.c om...
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
The string is 25/01/2005 (english format)
Thanks, Diego.

Nov 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.