HighDots Forums  

Re: Credit card validation routine

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Re: Credit card validation routine in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
noone
 
Posts: n/a

Default Re: Credit card validation routine - 08-20-2004 , 01:47 AM






Hi dries

"dries" <dries (AT) driesbessels (DOT) removebeforeuse.com> skrev i en meddelelse
news:jihph0dpgdsaf340odb79pjbcdeskuv47s (AT) 4ax (DOT) com...
Quote:
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!
...

Quote:
//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;
...
How about only copying the code which does the date checking, all the rest
isnīt of any interest.
Anyway your friends problem is simple.
You have to check month and year seperatedly.

First check the year:" CCyear > thisyear " then everything's fine cause the
card doesnīt expire this your or hasnnīt expired yet
then check for if "CCyear ==thisyear" you have to check the month, if the
month checks out:" CCmonth>=thismonth " everythings allright. the remaining
case is CCyear< thisyear, so you can return false.
Hope tha gets you on the way

Robert


Question: How can you recognize a programmers keyboard?
Answer: Three keys are worn out... <Ctrl>, <C> and <V>.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.