Solved

Range validator, used for dates

Posted on 2004-09-22
9
1,542 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
  • 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
 
LVL 2

Expert Comment

by:netjkus
ID: 12122461
Also you can change the separators as / or . or anything you like.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 50 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now