?
Solved

Range validator, used for dates

Posted on 2004-09-22
9
Medium Priority
?
1,553 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
Technology Partners: 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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

765 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