<table border="1">
<tr>
<td>
<label for="month">Expiration Month</label>
<select name="month">
<script language="JavaScript" type="text/javascript">
var month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");
for (var m=0; m<month.length; m++)
{
document.write("<option>" +month[m]+ "</option>");
}
</script>
</select>
</td>
<td>
<label for="year">Expiration Year</label>
<select name="year">
<script language="JavaScript" type="text/javascript">
var year = new Date();
var year2 = year.getFullYear();
for (y=0; y<6; y++)
{
document.write("<option>" +(year2+y)+ "</option>");
document.write("<br />");
}
</script>
</select>
</td>
</tr>
<tr><td>
<input type="submit" value="Submit">
<input type="reset" value="reset">
</tr>
</td>
</form>
</table>
</div>
</body>
</html>
views:
148answers:
1
+4
A:
Here's the first response i got when searching for "credit card expiration validation javascript" on Google.
http://perezj.blogspot.com/2008/02/credit-card-expiration-date-validation.html
Always makes me wonder why people post questions on StackOverflow before doing a search on the internet themselves.
Here's the function (if the link doesnt work):
function ValidateExpDate()
{
var ccExpYear = 20 + $F('<%= txtCCExpirationYear.ClientID%>');
var ccExpMonth = $F('<%= txtCCExpirationMonth.ClientID%>');
var expDate=new Date();
expDate.setFullYear(ccExpYear, ccExpMonth, 1);
var today = new Date();
if (expDate<today)
{
// Credit Card is expire
return false;
}
else
{
// Credit is valid
return true;
}
}
RPM1984
2010-06-09 04:28:41
+1 - A good developer should make an effort to find the answer themselves. On the other side, people consider SO as the definite and credible source for programming queries, just like experts-exchange used to be back in the days, before they filled up all pages with ads and hid the answers. SO shows up in the top results for most programming related searches. So cataloging this on SO seems perfectly normal to me for future users bumping across this problem.
Anurag
2010-06-09 05:23:40
that link's not working for me, but alas! i'm in china >:(
sfjedi
2010-07-29 20:24:58
@sfjedi - Pasted the function for you.
RPM1984
2010-07-30 00:17:13
@RPM1984 Thanks a lot!
sfjedi
2010-07-30 08:30:42