Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Range validator, used for dates

Posted on 2004-09-22
9
Medium Priority
?
1,564 Views
Last Modified: 2008-01-09
I am in the UK and my macine is configured as such.

I am using a range validator and want to use dd mm yyyy format for accepting dates.
I get a fairly generic "can't do that" type exception when I use this format for setting the minValue or maxValue properties for the range validator. How can I force it to accept my format?
0
Comment
Question by:philjh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12121804
0
 
LVL 4

Expert Comment

by:Andre412
ID: 12122411
Where are you applying this range validator ? on a form object, in a database or as a variable in code?

If you want to check dates in your specified format you can do as follows

        Dim mydate As DateTime = Now.ToShortDateString
        Dim anotherdate As DateTime = mydate.AddDays(1)
        MsgBox(mydate & " " & anotherdate)

toshortdate is automatically in the format you require

if you are applying this to form objects you can use afterupdate events to perform validations

on the other hand you can continue using a range validator control in which case this article may help you

http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=46
0
 
LVL 2

Expert Comment

by:netjkus
ID: 12122452
Here is the regular expression.. for dd/mm/yyyy format. This accepts the widest range of valid dates and mandates the date to be in 09 (not 9) format as well.


(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d

add this in the regularexpression text.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:netjkus
ID: 12122461
Also you can change the separators as / or . or anything you like.
0
 

Author Comment

by:philjh
ID: 12123386
Thanks for the comments, but what I'm asking is how can I get the range Validator to accept that it might have to exist outside the US.

I've set its Type to Date and pointed at a textbox. When I set the MaxValue and Minvalue to dd mm yyyy format and try to run the page I get(as soon as I try to run the page):

System.Web.HttpException: The value '31/12/2000' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Date'

I then tried :
Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")

which I put in Global.asax.

This allows the code to compile, but as soon as I enter a date into the textbox and move out of it, I get the same error as above.

PS. The question is about the range validator not the regularexpression validator.
PPS. I'm trying to avoid doing the checks in code, as I assume that's why the Range Validator exists in the first place.
Please feel free to answer "it doesn't do that because it's crap" if you feel it's appropriate.

Cheers.

0
 
LVL 2

Accepted Solution

by:
netjkus earned 200 total points
ID: 12123480
I have an application (that uses text field) to get the date. We tried to get the dates in particular format. And the dates should be valid. So we have used this regular expression to validate. However, you can combine both regular express and Range to validate your dates. First one should validate the required, then the regular expression and then the date Range validation.
Here is an example.
<asp:RangeValidator id="valRange" runat="server"
    ControlToValidate="textbox1"
    MaximumValue="12/31/1998"
    MinimumValue="01/01/1998"
    Type="Date"
    ErrorMessage="* The date must be between 01/01/1998 and 12/13/1998" Display="static">*</asp:RangeValidator>


ps. please increase points; if you need more code samples.. or post your code here to get an definite answer.
0
 
LVL 7

Expert Comment

by:vnvk
ID: 12130785
3 open questions:
09/22/04 http://www.experts-exchange.com/Q_21140455.html "Range validator, used for dates"
03/24/04 http://www.experts-exchange.com/Q_20930170.html "User control positioning"
03/11/04 http://www.experts-exchange.com/Q_20915054.html "Default button in asp.net"
0
 

Author Comment

by:philjh
ID: 12131641
Thanks
0
 
LVL 7

Expert Comment

by:vnvk
ID: 12131694
Thanks for following the suggestion and closing the questions
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question