A textbox in an HTML Form has 01/04/2001 (in DD-MM-YYYY) format as its default value which can be changed by the user. In order to ensure that users enter a valid date (for eg. 41/04/2001 would be invalid!!), how do I validate the date using ASP? What I tried is this:
<%
Dim dtFPeriod
dtFPeriod=Request.Form("fperiod"
If(Month(dtFPeriod)=1 OR Month(dtFPeriod)=3 OR Month(dtFPeriod)=5 OR Month(dtFPeriod)=7 OR Month(dtFPeriod)=8 OR Month(dtFPeriod)=10 OR Month(dtFPeriod)=12) Then
If(Day(dtFPeriod)>31 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
ElseIf(Month(dtFPeriod)=4 OR Month(dtFPeriod)=6 OR Month(dtFPeriod)=9 OR Month(dtFPeriod)=11) Then
If(Day(dtFperiod)>30 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
If Not(Year(dtFPeriod) Mod 4=0) Then
If(Month(dtFPeriod)=2) Then
If(Day(dtFPeriod)>28 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
Else
If(Month(dtFPeriod)=2) Then
If(Day(dtFPeriod)>29 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
End If
%>
Now if a valid date is entered by the user, then there is no problem but if, say, a user enters the date as 41/04/2001 then ASP throws the following error:
Type Mismatch: '[string: "41/04/2001"]'
which points to the very first If condition. So how do I validate the date users input using ASP?
Thanks,
Arpan
<%
Dim dtFPeriod
dtFPeriod=Request.Form("fperiod"
If(Month(dtFPeriod)=1 OR Month(dtFPeriod)=3 OR Month(dtFPeriod)=5 OR Month(dtFPeriod)=7 OR Month(dtFPeriod)=8 OR Month(dtFPeriod)=10 OR Month(dtFPeriod)=12) Then
If(Day(dtFPeriod)>31 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
ElseIf(Month(dtFPeriod)=4 OR Month(dtFPeriod)=6 OR Month(dtFPeriod)=9 OR Month(dtFPeriod)=11) Then
If(Day(dtFperiod)>30 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
If Not(Year(dtFPeriod) Mod 4=0) Then
If(Month(dtFPeriod)=2) Then
If(Day(dtFPeriod)>28 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
Else
If(Month(dtFPeriod)=2) Then
If(Day(dtFPeriod)>29 OR Day(dtFPeriod)<=0) Then
Response.Write("Invalid Date"
End If
End If
End If
%>
Now if a valid date is entered by the user, then there is no problem but if, say, a user enters the date as 41/04/2001 then ASP throws the following error:
Type Mismatch: '[string: "41/04/2001"]'
which points to the very first If condition. So how do I validate the date users input using ASP?
Thanks,
Arpan