HTML and CSS Reference
In-Depth Information
is used by a particular card type, whether the entire number fits a certain formula, and
valid expiration dates. For preliminary checking, you can test, for example, to see if a
person enters valid digits for a Visa card and that the expiration date is later than the
current date, but you can't really tell if the user's card has gone over the limit, was can-
celled or stolen, or that he or she even owns it. Checking whether the card is active
and has a sufficient balance to cover a sale is performed by the banking system backing
the card.
The Expiration Date of the Card. A valid expiration date is a month and year that
haven't gone by. The month and year are represented as two digits: 01 for January, 11
for November, and 03 for the year 2003. The following example defines a function to
test for a valid expiration date based on a one- to two-digit month and a two-digit or
four-digit year.
EXAMPLE 17.46
<html>
<head><title>Testing Expiration Dates</title>
<script type="text/javascript">
1
function validExpire(form) {
2
var now = new Date();
3
var thismonth = (now.getMonth() + 1);
4
var thisyear = now.getFullYear() ;
5
var expireYear = parseInt(form.expireYear.value);
var yearLength = form.expireYear.value.length;
var expireMonth = parseInt(form.expireMonth.value);
if( yearLength == 2 ){
expireYear += 2000;
}
6
if ((expireMonth < thismonth && expireYear == thisyear)
|| expireMonth > 12){
alert("Invalid month");
return false;
}
7
else if ( expireYear < thisyear) {
alert("Invalid year");
return false;
}
else {
return true;
}
}
</script>
</head>
4. For a guide to credit card validation software, go to http://www.winsite.com/business/cc/ .
Search WWH ::




Custom Search