[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

show error message if user enter dates beyond the date range

Posted on 2007-08-08
6
Medium Priority
?
584 Views
Last Modified: 2013-11-05
Hi there!,

            I have a textbox where the user enters date. The textbox can only accept dates betweeen 3/17/08 and 06/16/08. If the user enters date before 3/17/08 and after 06/16/08, then I would have to show an error message. This textbox is not a required field and can be left blank. But if the date the user enters is not within the specified dates, then I will have to show them an error. Thanks in advance.
0
Comment
Question by:siddhuoops
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 19655588
Consider using .NET's calendar control and built-in date range validation. That will save you a lot of work.
0
 

Author Comment

by:siddhuoops
ID: 19655608
how can I use the built in date range validation from a calendar control? Could you give me an example?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19655633
Example:

            DateTime dt1 = new DateTime(2008, 3, 17);
            DateTime dt2 = new DateTime(2008, 6, 18);

            DateTime dt = DateTime.Parse(this.textBox1.Text);

            if (dt < dt1 || dt > dt2)
                MessageBox.Show("Invalid date entered");

Bob
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:siddhuoops
ID: 19655686
Hey Bob, this code works fine but what if the user does not enter anything in the box. Since, the textbox is not a required field.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19655827
Is skipping an option?

         if (this.textBox1.Text.Trim().Length > 0)
        {
            DateTime dt1 = new DateTime(2008, 3, 17);
            DateTime dt2 = new DateTime(2008, 6, 18);

            DateTime dt = DateTime.Parse(this.textBox1.Text);

            if (dt < dt1 || dt > dt2)
                MessageBox.Show("Invalid date entered");
         }

Bob
0
 

Author Comment

by:siddhuoops
ID: 19656542
thanks Bob!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Integration Management Part 2
Loops Section Overview

834 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