PDA

View Full Version : Expiry Date Validation


dude9er
05-20-2006, 01:07 AM
I have created a Credit Card Form and I am trying to validate the Expiry Date:


<select name="CC_expmonth" id="CC_expmonth" value="<%=CC_expmonth%>">
<option value="<%=CC_expmonth%>" selected="<%=CC_expmonth%>"><%=CC_expmonth%></option>
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Mar">Mar</option>
<option value="Apr">Apr</option>
<option value="May">May</option>
<option value="Jun">Jun</option>
<option value="Jul">Jul</option>
<option value="Aug">Aug</option>
<option value="Sep">Sep</option>
<option value="Oct">Oct</option>
<option value="Nov">Nov</option>
<option value="Dec">Dec</option>
</select>
<input name="r_CC_expmonth" type="hidden" id="r_CC_expmonth" value="Credit Card Expiry Month" />
<select name="CC_expyear" id="CC_expyear" value="<%=CC_expyear%>">
<option value="<%=CC_expyear%>" selected="<%=CC_expyear%>"><%=CC_expyear%></option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select>
</span>
<input name="r_CC_expyear" type="hidden" id="r_CC_expyear" value="Credit Card Expiry Year" />
</span><span class="style2"><br />
<%=Reason3 %></span></td>




I would like to have the my add_to_database.asp script validate the expiry date drop down.

1. If user selects <Select name="CC_expmonth"> with values of <"value=Jan", "value=Feb", "value=Mar", "value=Apr" "value=May">

AND

If user selects <Select name="CC_expyear"> with value of <"value=2006">

and EXPIRED CC ERROR message will occur.

Here is what I have but I can't seem to get it to work.


if CC_expyear = "2006" AND Len("CC_expmonth") <> (Request.Form("Jan", "Feb", "March")) THEN
Reason3 = "Credit Card Expired."
InputError=InputError+1
end if


Is there a way of identifying the current DATE and comparing that to the values (Jan, Feb etc) in CC_expmonth and able to apply an error message ???

I'm new to ASP and am learning quite a bit, but have not been able to resolve this issue.

THANKS EVERYONE!!!!

mehere
05-20-2006, 02:23 AM
you could try something like this:

if request("CC_expyear") <= year(date()) then
if CC_expmonth < DatePart("m",Date())) then
Reason3 = "Credit Card Expired."
InputError=InputError+1
end if
end if

but i think you may need to change the values in your drop down for month to numbers and not words like this:
<option value="1">Jan</option>

dude9er
05-20-2006, 04:59 PM
mehere, I tried the above code and it doesn't seem to work. I'm getting this error:


Microsoft VBScript compilation error '800a03f9'

Expected 'Then'

/nra/add_to_database_test33.asp, line 523

if CC_expmonth < DatePart("m", Date())) then
--------------------------------------^


Any way to resolve this? Thanks for you help so far!!

ghell
05-20-2006, 10:01 PM
Remove the close parenthesis its pointing at (the line has 2 opens but 3 closes)

also note that you can use Month() in the same way as Year() is used in the first line.

If Request.Form("CC_expyear") < Year(Date()) Then
Response.Write "Year too early. no point checking month."
Response.End
ElseIf Request.Form("CC_expmonth") <= Month(Date()) AND Request.Form("CC_expyear") = Year(Date()) Then
Response.Write "Year was ok but month is too early."
Response.End
Else
Response.Write "expiry ok"
End Iftheres some sample logic :)

A better solution may be
Dim dtmExpiryDate
dtmExpiryDate = CDate(Request.Form("CC_expyear") & "-" & Request.Form("CC_expmonth") & "-" & "-01")
If dtmExpiryDate < Date() Then
Response.Write "Expired Card."
Response.End
Else
Response.Write "Valid expiry"
End Ifhowever this would validate against the first of the month not the last (can't remember the easy way of gettnig number of days in a given month/year) so it would need slight alteration.. could just add 1 month and subtract 1 day i suppose ;) that would be using a DateAdd() around the CDate() and then sticking a -1 at the end of the line :D

dude9er
05-20-2006, 11:57 PM
I can't seem to figure this darn thing out.

I have an asp page called
"index2.asp"

The form is submitted and form valuess are carried over to a second form called
"CCpage2.asp"

CCpage2.asp when submitted is validated through "add_to_database_test33.asp"

If all fields are correct then the form values are written to the database. If there is an error the "add_to_database_test33.asp" sumits to itself, field values from previous submit attempt are carried over via <%=fieldname%>. Once all fields are correct the form submits and the user is redirected.

I am not able to figure out the CC Expires validation. I've attached a zip for review. I can't seem to get anyone's suggestions working. Please view

add_to_database_test33.asp and refer to lines 518-521 for expiry validation.

Can someone PLEASE help me with this. This is the only part of the form I need fixed before monday.

THANKS!!!!

Here is an online version for review

http://charity-funding.us/nra/index2.asp