Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

time field validation in a form

Status
Not open for further replies.

joyceda59

Technical User
Apr 3, 2007
29
0
0
CA
Hi...

I am creating this form validation process that allows to a time that is inputted by the user. Basically, I have this field that asks for a user to enter a time (format is specified as. Ex: "12:00 PM"). I want to make sure that the user types in a time with the appropriate format. After i completed my code, i keep receiving a type mismatch error. The error is specified on the line with the split function. Please help!..thx


Here is my code:

distTime = Request("time")

Dim strTimeArray(2)

strTimeArray = Split(distTime,": ")


if disTime <> "" Then

intTimeHour = CInt(strTimeArray(0))
intTimeMinutes = CInt(strTimeArray(1))

if intTimeHour < 0 OR intTimeHour > 12 Then

Response.Write "<center><b> The distribution time is not appropriate. Check the hours column</b></center>"

end if

if intTimeMinutes <0 OR intTimeMinutes > 59 Then

Response.Write "<center><b> The distribution time is not appropriate. Check the minutes column</b></center>"
end if

if strTimeArray(3) <> "AM" OR strTimeArray(3) <> "am" OR strTimeArray(3) <> "PM" OR strTimeArray(3) <> "pm" Then

Response.Write "<center><b> The distribution time is not appropriate. Check the AM/PM column</b></center>"
end if
end if
 
you don' tneed to define timearray with dim.
when you use split, it is defined as an array anyway.
 
A regular expression may be good for this.

Code:
Function VerifyDate(strInput)
	Dim RegEx : Set RegEx = New RegExp
	RegEx.Pattern = "^(([0][0-9]|[1][0-2])|[0-9]):([0-5][0-9]) (AM|PM)$"
	RegEx.IgnoreCase = True
	RegEx.Global = True
	VerifyDate = RegEx.Test(strInput)
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Hey..i include the regular expression into my code and then called the function in the sub that does all the other form validation...but for some reason the time validation is not working. When i type in out of range numbers in the time field, i m still able to submit the form. Here is what i did:

I just included the line

VerifyDate(distTime)

into the sub
 
It should be something like

If VerifyDate(distTime) Then
' do something
Else
' give an error
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top