Solved

Range validator, used for dates

Posted on 2004-09-22
9
1,545 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
consuming an asmx web service in winforms application 3 41
ASP.NET 5 Templates 2 78
asp day pilot 3 19
IIS redirect 1 68
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 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