Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Old 02-22-2007, 03:22 PM Date validation
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
I was wonder how I would go about making sure something within a text box is a valid date. I know that usually I would use JavaScript but I don’t know if that’s possible to use within an asp page. I would also imagine that using asp there would be another way of validating a date anyway without have to introduce another language.

From various Google searches I have found a few things that didn’t work. Mainly people are saying use the IsDate function, but that won’t tell you if it’s a VALID date but only if it IS a date.

I’m also looking to see if the dates not in the past, I don’t think this will be hard after I find a way to validate it though.

Other information: The format will be mm/dd/yyyy

The_Anomaly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-22-2007, 03:53 PM Re: Date validation
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
First, IsDate will tell you whether something is a valid date or not, it's just you have your own definition of valid. But try passing January 41, 2104 and it'll say no way Jose. Also, JavaScript is indeed the way to go here, because it can be done on the client end without having to make a round trip to your web server. And absolutely you can mix JS and ASP. But you seem uncomfortable with the idea, so I'll show you how to do it in ASP using VBScript, and then you can move on when you're ready.

Public Function IsOkayDate(someValue As String) As Boolean
If IsDate(someValue) Then If CDate(someValue) > Now() Then If Format(CDate(someValue), "mm/dd/yyy") = someValue Then Return True
Return False
End Function

Okay, what do I win?
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-22-2007, 03:56 PM Re: Date validation
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use a regular expression
The pattern for mm/dd/yyyy is
Code:
"(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d"

and a function from my code library is;
Code:
function CheckDate(strIn)
' function to validate date input
	dim objRE
	set objRE = New RegExp
	objRE.Pattern = "(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d"
	objRE.Global = True
	CheckDate = objRE.test(strIn)
	set objRE = nothing
end function
It will return true is the date is valid and false is not
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-22-2007, 05:00 PM Re: Date validation
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
It seems my problem now is how do i call this. I was thinking, on the submit i would move to an invisible page that would do all of the validation then if its valid redirect to the next page, if it wasnt go back and show where the errors were. cleint side/server side isnt a big deal since this will be for an in-house help desk site for a company of ~60
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Old 02-23-2007, 01:07 AM Re: Date validation
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
http://truegeeks.com/asp/aspexamples/gendate/edate1.asp <--- I don't normally recommend scripts, but this one isn't bad as long as you tweak it a bit.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to Date validation
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.55668 seconds with 12 queries