469,333 Members | 4,185 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

Date Validation

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
12 3021
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
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
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
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
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
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
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
The string is 25/01/2005 (english format)
Thanks, Diego.
Nov 19 '05 #9
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
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
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

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.

Similar topics

30 posts views Thread by Dr John Stockton | last post: by
reply views Thread by Brian Conway | last post: by
7 posts views Thread by Paul | last post: by
1 post views Thread by Brendan Reynolds | last post: by
3 posts views Thread by =?Utf-8?B?Q2hyaXM=?= | last post: by
2 posts views Thread by John Smith | last post: by
Stang02GT
5 posts views Thread by Stang02GT | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.