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.
<head><title>Testing Expiration Dates</title>
<script type="text/javascript">
function validExpire(form) {
var now = new Date();
var thismonth = (now.getMonth() + 1);
var thisyear = now.getFullYear() ;
var expireYear = parseInt(form.expireYear.value);
var yearLength = form.expireYear.value.length;
var expireMonth = parseInt(form.expireMonth.value);
if( yearLength == 2 ){
expireYear += 2000;
if ((expireMonth < thismonth && expireYear == thisyear)
|| expireMonth > 12){
alert("Invalid month");
return false;
else if ( expireYear < thisyear) {
alert("Invalid year");
return false;
else {
return true;
4. For a guide to credit card validation software, go to .
Search WWH ::

Custom Search