473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3245
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format, as this was the only format that Oracle would...
7
by: Paul | last post by:
Hi, I have a form where a user is required to enter a start date and an end date. Both are required and must between a specific date range (e.g. 01/01/1900 and 01/01/2099) and the end date...
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
1
by: Brendan Reynolds | last post by:
In an ASP.NET 1.1 app I have the following range validation control. This is an intranet app that will be used only within Ireland, so all date input is expected to be in dd/mm/yyyy format. ...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
3
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I have VS 2005 (C#) There is a control numericUpDown so you can spin numeric values. What I need to do is to spin date (+- one day). How to do that? Moreover, I want a user to type the date as...
2
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date validation check after the the field is updated, so...
5
Stang02GT
by: Stang02GT | last post by:
I have been asked to validate a date on our web-page so that people cannot enter dates like 14/1/08 or 2/30/06. I have found code that will do exactly what i need it to do, but i am not sure how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.