Solved

Range validator, used for dates

Posted on 2004-09-22
9
1,543 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

947 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

22 Experts available now in Live!

Get 1:1 Help Now