D
dries
A friend of mine has a problem with his credit card validation routine
and it is probably a simple thing to solve but I cannot find it.
It has to do with the expiry dates.
What happens is that as each month passes, that month is then not
recognised as being valid, even though the year makes it still valid.
i.e. the number of the month entered has to be bigger than the number
of the current month. Therefor, if it is in august now 09/2005 wil be
valid but
08/2005 will be rejected.
Below quoted is the code, could anybody make sense of this problem?
Thanks!
<HTML>
<HEAD><TITLE>Secure Credit Card Transaction</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFF00">
<script language="JAVASCRIPT">
<!--
//This function validates entry credit card
information
function _vet(){
var thisyear;
var thismonth;
var thisdate;
var CCname = document.Final.CardHolder.value;
var CCmonth =
document.Final.ExpMonth.options[document.Final.ExpMonth.selectedIndex].value;
var CCyear =
document.Final.ExpYear.options[document.Final.ExpYear.selectedIndex].value;
var CCval = document.Final.CCNo.value;
var CCtype =
document.Final.CreditCard.options[document.Final.CreditCard.selectedIndex].value;
var failed = false;
// check if credit card name has been entered
if (failed == false)
{
if (CCname == "")
{
alert("Please enter name on card");
failed = true;
}
}
// check if credit card number has been entered
if (failed == false)
{
if (CCval == "")
{
alert ("Please enter credit card number");
failed = true;
}
}
// check if credit card type has been entered
if (failed == false)
{
if (CCtype == " ")
{
alert("Please select credit card type");
failed = true;
}
}
//Check if card expiry month has been entered
if (failed == false)
{
if (CCmonth == "Mn")
{
alert("Please enter credit card expiry month");
failed = true;
}
}
//Check if card expiry year has been entered
if (failed == false)
{
if (CCyear == "Yr")
{
alert("Please enter credit card expiry year");
failed = true;
}
}
CCval = _strip_spaces(CCval);
// check if credit card number is actually a number
if (_isinteger(CCval) == false)
{
alert("Credit Card number must be a numeric value only
with or without spaces in between the groups of numbers");
failed = true;
}
if (failed == false)
{
// check for 4242 4242 4242 4242
if (CCval == "4242424242424242")
{
alert ("The credit card number you supplied is
incorrect");
failed = true;
}
}
if (failed == false)
{
}
if (failed == false)
{
//check that the credit card number is valid
if (CC_Validate(CCval) == true)
{
//now check that the date is valid i.e. greater or equal to now
thisdate = new Date();
thisyear = thisdate.getYear() + 1900;
thismonth = thisdate.getMonth();
if ((CCmonth <= thismonth) && (CCyear <=
thisyear))
{
alert("Your credit card has expired");
failed = true;
}
}
else
{ alert("The credit card number you supplied is
incorrect");
failed = true;
}
if (failed == false)
document.Final.submit();
}
}
function _strip_spaces(_ipstr)
{
var _opstr = '';
var i;
for (i = 1; i <= _ipstr.length; i++)
{
if(_ipstr.substring(i-1, i) != ' ')
_opstr = _opstr + _ipstr.substring(i-1, i);
}
return _opstr;
}
function _isinteger(test_string){
var i;
var non_nums = 0;
for (i = 1; i < test_string.length; i++){
if ((test_string.substring(i-1,i) < '0') ||
(test_string.substring(i-1,i) > '9'))
non_nums++;
}
if (non_nums == 0)
return true;
else
return false;
}
function CC_Validate(ccnumber){
var checksum = 0;
var i;
var digit;
var temp;
var cclength=ccnumber.length;
if (cclength % 2 != 0)
{
cclength += 1;
ccnumber = "0" + ccnumber;
}
for (i = 0; i < cclength; i++){
digit = parseInt(ccnumber.charAt(i));
if ((i % 2) == 0){
digit *= 2;
if (digit > 9)
digit = parseInt(digit / 10) + parseInt(digit
% 10);
}
checksum += digit;
}
if (checksum % 10 == 0)
return true;
else
return false;
}
//-->
</script>
<FORM METHOD = "POST" ACTION = "process.cfm" NAME = "Final">
<INPUT TYPE = "HIDDEN" NAME = "MEMBERSHIP"
VALUE = " ">
<INPUT TYPE = "HIDDEN" NAME =
"APPLICATION_TYPE" VALUE = " ">
<INPUT TYPE = "HIDDEN" NAME = "TITLE1" VALUE
= " ">
<INPUT TYPE = "HIDDEN" NAME = "FIRST_NAME1"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "LAST_NAME1"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "TITLE2" VALUE
= " ">
<INPUT TYPE = "HIDDEN" NAME = "FIRST_NAME2"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "LAST_NAME2"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "STREET" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "TOWN" VALUE =
"">
<INPUT TYPE = "HIDDEN" NAME = "REGION" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "POST_CODE"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "COUNTRY" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "TELEPHONE_NO"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "FAX_NO" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "EMAIL_ADDRESS"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "COMMENTS"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "WHERE_FROM"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "OTHER" VALUE =
"">
<INPUT TYPE="HIDDEN" NAME="SS_TO" VALUE="(e-mail address removed)">
<INPUT TYPE="HIDDEN" NAME="SS_SUBJECT" VALUE="Membership Credit Card
Secure Order">
<INPUT TYPE="HIDDEN" NAME="SS_NEXTPAGE"
VALUE="http://website/thanks.html">
<CENTER><FONT FACE="Comic Sans MS" SIZE="+2"
COLOR="#FF0000"><B><I>Your Credit Card Details</I></B></FONT></CENTER>
<BR>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Please enter your
Credit Card details below. To avoid any unnecessary delays to your
order, please verify that all your card details are correct before
clicking the "Make Payment" button. Thank you.</FONT>
<HR WIDTH="100%" ALIGN="Center" SIZE="2">
<table>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Name On Card
:</font></td>
<td><input name="CardHolder" size=50 maxlength=50></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Card Number
:</font></td>
<td><input name="CCNo" size="25"></font></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Card Type
:</font></td>
<td><select name="CreditCard">
<option value=" ">
<option>VISA
<option>Mastercard
</select></td>
</tr>
<tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Expiry Date
:</font></td>
<td>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Month</font>
<SELECT NAME = "ExpMonth">
<OPTION VALUE = "Mn">Mn</OPTION>
<OPTION VALUE = "01">01</OPTION>
<OPTION VALUE = "02">02</OPTION>
<OPTION VALUE = "03">03</OPTION>
<OPTION VALUE = "04">04</OPTION>
<OPTION VALUE = "05">05</OPTION>
<OPTION VALUE = "06">06</OPTION>
<OPTION VALUE = "07">07</OPTION>
<OPTION VALUE = "08">08</OPTION>
<OPTION VALUE = "09">09</OPTION>
<OPTION VALUE = "10">10</OPTION>
<OPTION VALUE = "11">11</OPTION>
<OPTION VALUE = "12">12</OPTION>
</SELECT>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Year</font>
<SELECT NAME = "ExpYear">
<OPTION VALUE = "Yr">Yr</OPTION>
<OPTION value = "1998">1998</OPTION>
<OPTION value = "1999">1999</OPTION>
<OPTION value = "2000">2000</OPTION>
<OPTION value = "2001">2001</OPTION>
<OPTION value = "2002">2002</OPTION>
<OPTION value = "2003">2003</OPTION>
<OPTION value = "2004">2004</OPTION>
<OPTION value = "2005">2005</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>
</SELECT>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td><INPUT TYPE = "Button" VALUE = " Make Payment" OnClick =
"_vet()"></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td align=left><INPUT TYPE = "Reset"></td>
</tr>
</table>
</FORM>
<BR>
<BR>
</HTML>
and it is probably a simple thing to solve but I cannot find it.
It has to do with the expiry dates.
What happens is that as each month passes, that month is then not
recognised as being valid, even though the year makes it still valid.
i.e. the number of the month entered has to be bigger than the number
of the current month. Therefor, if it is in august now 09/2005 wil be
valid but
08/2005 will be rejected.
Below quoted is the code, could anybody make sense of this problem?
Thanks!
<HTML>
<HEAD><TITLE>Secure Credit Card Transaction</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFF00">
<script language="JAVASCRIPT">
<!--
//This function validates entry credit card
information
function _vet(){
var thisyear;
var thismonth;
var thisdate;
var CCname = document.Final.CardHolder.value;
var CCmonth =
document.Final.ExpMonth.options[document.Final.ExpMonth.selectedIndex].value;
var CCyear =
document.Final.ExpYear.options[document.Final.ExpYear.selectedIndex].value;
var CCval = document.Final.CCNo.value;
var CCtype =
document.Final.CreditCard.options[document.Final.CreditCard.selectedIndex].value;
var failed = false;
// check if credit card name has been entered
if (failed == false)
{
if (CCname == "")
{
alert("Please enter name on card");
failed = true;
}
}
// check if credit card number has been entered
if (failed == false)
{
if (CCval == "")
{
alert ("Please enter credit card number");
failed = true;
}
}
// check if credit card type has been entered
if (failed == false)
{
if (CCtype == " ")
{
alert("Please select credit card type");
failed = true;
}
}
//Check if card expiry month has been entered
if (failed == false)
{
if (CCmonth == "Mn")
{
alert("Please enter credit card expiry month");
failed = true;
}
}
//Check if card expiry year has been entered
if (failed == false)
{
if (CCyear == "Yr")
{
alert("Please enter credit card expiry year");
failed = true;
}
}
CCval = _strip_spaces(CCval);
// check if credit card number is actually a number
if (_isinteger(CCval) == false)
{
alert("Credit Card number must be a numeric value only
with or without spaces in between the groups of numbers");
failed = true;
}
if (failed == false)
{
// check for 4242 4242 4242 4242
if (CCval == "4242424242424242")
{
alert ("The credit card number you supplied is
incorrect");
failed = true;
}
}
if (failed == false)
{
}
if (failed == false)
{
//check that the credit card number is valid
if (CC_Validate(CCval) == true)
{
//now check that the date is valid i.e. greater or equal to now
thisdate = new Date();
thisyear = thisdate.getYear() + 1900;
thismonth = thisdate.getMonth();
if ((CCmonth <= thismonth) && (CCyear <=
thisyear))
{
alert("Your credit card has expired");
failed = true;
}
}
else
{ alert("The credit card number you supplied is
incorrect");
failed = true;
}
if (failed == false)
document.Final.submit();
}
}
function _strip_spaces(_ipstr)
{
var _opstr = '';
var i;
for (i = 1; i <= _ipstr.length; i++)
{
if(_ipstr.substring(i-1, i) != ' ')
_opstr = _opstr + _ipstr.substring(i-1, i);
}
return _opstr;
}
function _isinteger(test_string){
var i;
var non_nums = 0;
for (i = 1; i < test_string.length; i++){
if ((test_string.substring(i-1,i) < '0') ||
(test_string.substring(i-1,i) > '9'))
non_nums++;
}
if (non_nums == 0)
return true;
else
return false;
}
function CC_Validate(ccnumber){
var checksum = 0;
var i;
var digit;
var temp;
var cclength=ccnumber.length;
if (cclength % 2 != 0)
{
cclength += 1;
ccnumber = "0" + ccnumber;
}
for (i = 0; i < cclength; i++){
digit = parseInt(ccnumber.charAt(i));
if ((i % 2) == 0){
digit *= 2;
if (digit > 9)
digit = parseInt(digit / 10) + parseInt(digit
% 10);
}
checksum += digit;
}
if (checksum % 10 == 0)
return true;
else
return false;
}
//-->
</script>
<FORM METHOD = "POST" ACTION = "process.cfm" NAME = "Final">
<INPUT TYPE = "HIDDEN" NAME = "MEMBERSHIP"
VALUE = " ">
<INPUT TYPE = "HIDDEN" NAME =
"APPLICATION_TYPE" VALUE = " ">
<INPUT TYPE = "HIDDEN" NAME = "TITLE1" VALUE
= " ">
<INPUT TYPE = "HIDDEN" NAME = "FIRST_NAME1"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "LAST_NAME1"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "TITLE2" VALUE
= " ">
<INPUT TYPE = "HIDDEN" NAME = "FIRST_NAME2"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "LAST_NAME2"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "STREET" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "TOWN" VALUE =
"">
<INPUT TYPE = "HIDDEN" NAME = "REGION" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "POST_CODE"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "COUNTRY" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "TELEPHONE_NO"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "FAX_NO" VALUE
= "">
<INPUT TYPE = "HIDDEN" NAME = "EMAIL_ADDRESS"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "COMMENTS"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "WHERE_FROM"
VALUE = "">
<INPUT TYPE = "HIDDEN" NAME = "OTHER" VALUE =
"">
<INPUT TYPE="HIDDEN" NAME="SS_TO" VALUE="(e-mail address removed)">
<INPUT TYPE="HIDDEN" NAME="SS_SUBJECT" VALUE="Membership Credit Card
Secure Order">
<INPUT TYPE="HIDDEN" NAME="SS_NEXTPAGE"
VALUE="http://website/thanks.html">
<CENTER><FONT FACE="Comic Sans MS" SIZE="+2"
COLOR="#FF0000"><B><I>Your Credit Card Details</I></B></FONT></CENTER>
<BR>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Please enter your
Credit Card details below. To avoid any unnecessary delays to your
order, please verify that all your card details are correct before
clicking the "Make Payment" button. Thank you.</FONT>
<HR WIDTH="100%" ALIGN="Center" SIZE="2">
<table>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Name On Card
:</font></td>
<td><input name="CardHolder" size=50 maxlength=50></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Card Number
:</font></td>
<td><input name="CCNo" size="25"></font></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Card Type
:</font></td>
<td><select name="CreditCard">
<option value=" ">
<option>VISA
<option>Mastercard
</select></td>
</tr>
<tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<td><FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Expiry Date
:</font></td>
<td>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Month</font>
<SELECT NAME = "ExpMonth">
<OPTION VALUE = "Mn">Mn</OPTION>
<OPTION VALUE = "01">01</OPTION>
<OPTION VALUE = "02">02</OPTION>
<OPTION VALUE = "03">03</OPTION>
<OPTION VALUE = "04">04</OPTION>
<OPTION VALUE = "05">05</OPTION>
<OPTION VALUE = "06">06</OPTION>
<OPTION VALUE = "07">07</OPTION>
<OPTION VALUE = "08">08</OPTION>
<OPTION VALUE = "09">09</OPTION>
<OPTION VALUE = "10">10</OPTION>
<OPTION VALUE = "11">11</OPTION>
<OPTION VALUE = "12">12</OPTION>
</SELECT>
<FONT FACE="Comic Sans MS" SIZE="+1" COLOR="#0000FF">Year</font>
<SELECT NAME = "ExpYear">
<OPTION VALUE = "Yr">Yr</OPTION>
<OPTION value = "1998">1998</OPTION>
<OPTION value = "1999">1999</OPTION>
<OPTION value = "2000">2000</OPTION>
<OPTION value = "2001">2001</OPTION>
<OPTION value = "2002">2002</OPTION>
<OPTION value = "2003">2003</OPTION>
<OPTION value = "2004">2004</OPTION>
<OPTION value = "2005">2005</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>
</SELECT>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td><INPUT TYPE = "Button" VALUE = " Make Payment" OnClick =
"_vet()"></td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td align=left><INPUT TYPE = "Reset"></td>
</tr>
</table>
</FORM>
<BR>
<BR>
</HTML>