Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 12:20 PM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date/Time Error

How do I say, if a textbox doesn't equal the proper date format (mm/dd/yyyy) than throw an error.

I have tried Try and Catch statement but it is not working the way I want it to.

For Ex:
I have txtDOB.text, if txtDOB.text <> mm/dd/yyyy (some date) then
response.write an error message.

Any help is greatly appricated.

Thanks,
MGR

 
Old October 15th, 2004, 03:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

A normal query asked is to validate the date in a specific format. The sample code demonstrates to validate a date in a specific given format. Sample Below checks for the date given in mm/dd/yy or mm/dd/yyyy format.

The Namspace used in the demonstration is System.Globalization

Step 1: main.aspx

<asp:Button id="btnValidate" runat="server" Text="Validate Date"></asp:Button>
<asp:Label id="Label1" runat="server">Enter Date</asp:Label>
<asp:TextBox id="txtDate" runat="server"></asp:TextBox>


Step 2: main.aspx.vb

Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click

Try
     Dim myDateTimeUS As System.DateTime
     Dim format As New System.Globalization.CultureInfo("en-US", True)
     myDateTimeUS = System.DateTime.Parse(txtDate.Text, format)
     Response.Write("Valid Date")

Catch ex As Exception

     Response.Write(ex.Message)
     Response.Write("Not Valid Date")

End Try

(not tested)

Yippie Ki Yea, Mr. Falcon.
 
Old October 18th, 2004, 06:37 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hey stu9820, thanks for the reply.

However I am still having alittle trouble getting this to work from a checkDate function or on Page_Load instead of running it from a button as you have shown. I get it working from a button, with no troubles.

Thanks again,
Mark






Similar Threads
Thread Thread Starter Forum Replies Last Post
date and time in EST time zone anboss XSLT 1 May 21st, 2008 01:42 PM
Date-Time Picker Active-X Error Loralee Access 2 January 30th, 2006 08:22 PM
Date/Time Still getting error mrideout BOOK: Beginning ASP.NET 1.0 2 October 19th, 2004 07:20 AM
Microsoft Date and Time Picker - Error mikericc Access VBA 1 December 4th, 2003 04:15 PM
insert system date. no date and time jimmy Access VBA 6 November 20th, 2003 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.