ASP.net Date Validation

hellopal

New Member
Hello I'm using a date validation function in ASP for my credti card software. It helps me validate expiration dates (MM/YYYY format) Example: 12/2002. I'm using asp.net now and of course it doesnt work. I receive errors saying that it cant be in the method body. Here is the function:<BR>--------------------------------------------------<BR> Function GoodDate() <BR> GoodDate = True <BR> If Not IsDate(ExpireDate) Then <BR> GoodDate = False <BR> Else <BR> currdate = Month(Now()) & " " & Year(Now()) <BR> Response.Write curdate<BR> If DateValue(ExpireDate) < DateValue(currdate) Then <BR> GoodDate = False <BR> End If <BR> End If <BR> End Function <BR><BR>if GoodDate() then 'the date passed the test <BR>Response.write ("Blah Good")<BR>Else<BR>Response.write ("Blah BAD")<BR>End if<BR>---------------------------------------------------------<BR>Can anyone help me with this?I get this message whenever I try to put code in between <%...%> tags instead of <script runat="server">...</script>. You might want to try that instead.I agree! I also get the same results. But I'm a novice, how do I call the code/function residing in the </script> tags from the <%%> source code. If I can find that out, It'll be all I need.If you put the sub within the <script> tags you can call it normally in <% tags later in the page.You probably want to start doing things like this:<BR><BR><%@ Page Language="vb" Debug="true"%><BR><script runat="server"><BR><BR>Function GoodDate() <BR> dim currdate as date<BR> GoodDate = True <BR> If Not IsDate(ExpireDate.Value) Then <BR> GoodDate = False <BR> Else <BR> currdate = Month(Now()) & " " & Year(Now()) <BR> Response.Write(currdate )<BR> If DateValue(ExpireDate.value) < DateValue(currdate) Then <BR> GoodDate = False <BR> End If <BR> End If <BR>End Function <BR><BR>Private Sub subbtn_ServerClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)<BR> if GoodDate() then <BR> errorMessage.innerText="Blah Good"<BR> Else <BR> errorMessage.innerText="Blah BAD"<BR> End if <BR><BR>end sub<BR></script><BR><html><BR><body><BR><BR><form runat=server><BR><div id="errorMessage" runat=server></div><BR><input type=text id=ExpireDate runat="server" value=http://aspmessageboard.com/archive/index.php/"12 02"><BR><BR><input type="submit" id="subbtn" runat="server" onserverclick="subbtn_ServerClicked"><BR></form><BR><BR></body><BR></html>thanks. Thats exactly what I needed. The first answer was enough but this one just helps even more.
 
Back
Top