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 18th, 2004, 09:02 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Entering Date on web form

Hi, I have a web form, where I take in the user Date Of Birth (DOB) in a textbox in the form of mm/dd/yyyy.

However, if the user does not enter in the correct format user gets an error. This happens if the user enters "dd/mm/yyyy", "w", or any other letter. I add the DOB to my database on a function called AddUser. This is ran when I click the add button which runs the AddUser function.
I know that this isn't very hard, but I cannot get it to work!!

Please any help will be greatly appreciated.

Thanks in Advance,
Very frustrated!!


 
Old October 18th, 2004, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You could use Regular expressions:

Imports System.Text.RegularExpressions

..

If (Regex.IsMatch(txtDOB.Text, "(1[0-2]|[1-9])/(3[0-1]|[1-2]0|[1-2]?[1-9])/[1-2][0-9]{3,}")) Then
  'Valid
Else
  'Invalid
End If

There are probably better Regular expressions.

Brian
 
Old October 18th, 2004, 09:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I should also mention, that you won't be able to parse out users who enter the date:

3/10/2004

to actually mean October 3, 2004. It will see that as a valid date, because it is.

Brian
 
Old October 18th, 2004, 09:18 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey brian,

Thanks for the fact post...could you explain regular expression or get me a link where I may read-up on this.

As I am still relativity new to the .NET world, I never read or seen regular expressions before.

Thanks again.
Mark

 
Old October 18th, 2004, 09:49 AM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How do you suggest I go about validating the textbox for a valid date?

Mark

 
Old October 18th, 2004, 10:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Well, in my previous example, 3/10/2004 is a valid date. There isn't anything you can do to that extent...

http://msdn.microsoft.com/library/?u...xpressions.asp

http://search.yahoo.com/search?p=%2B...t-151&toggle=1

Brian
 
Old October 19th, 2004, 12:08 PM
Authorized User
 
Join Date: Jul 2004
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian,

I have it working now.
Mark






Similar Threads
Thread Thread Starter Forum Replies Last Post
Entering special characters on the form MyronCope Classic ASP Basics 1 November 21st, 2006 09:27 AM
set Focus to web control in Web form vivekshah C# 1 June 17th, 2006 03:25 AM
How to give Date format while entering date Subuana Beginning VB 6 4 March 17th, 2006 07:25 AM
Entering Multiple Sale Items on a Form rika4750 Access 1 May 2nd, 2005 12:48 PM
entering Null value for Date field jordancrandall Access ASP 1 January 12th, 2005 01:29 PM





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