473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What should be a relatively easy calc !?!?!?!

Hi All

Wonder if you can help me with the following calc, which I want to create to
check whether or not a user has entered a valid credit card expiry date:

1) I have retrieve a value from 2 x SELECTs. One value is the month in a 2
DIGIT form, eg 01, 02, 03, 04, etc, and the other is the year in a 4 DIGIT
form, ie 2004, 2005, 2006, 2007, etc.

2) My Maths for this was going to be that I do a calc on the figures
retrieved in the above point1 against figures retrieved for today's date, in
theory like the following:

expirydate = expirymonth + (expiryyear * 12) // this is for the expiry date
figures in point 1

currentdate = currentmonth + (currentyear * 12) // this is for today's date
figures.

If expirydate < currentdate then bring up a warnnig box that they can bypass
else drop out.

Because the expirydate and currentdate vars are standard ints this is a
straightforward calc, but my probs in getting this to work are as follows:

a) Because all of my months have 2 digits, ie 01, 02, .... 10, 11, 12, there
seems to be a problem calculating the ones that start with a zero, eg 01,
02, etc, but I need to keep to this 2 digit display.

b) My year is 4 digits, which I need to keep, so I need to chop it to 2.

c) I used the following to get today's month and year:

thedate = Date()
currentmonth = thedate.CurrentMonth()
currentyear = thedate.CurrentYear()

which seems to work, but then I can't seem to strip these down to the 1
digit month and 2 digit year that I am after AND use them in a straight
integer calc, eg currentdate = currentmonth + (currentyear * 12).

d) If the expirydate is less than the currentdate I wanted to display a
OK/Cancel box so that I can warn them of this, but if they click OK the
submit is true and goes through and if they click Cancel then the form is
false and the submit doesn't go through.

Can anybody advise me on the above?

Thanks

Robbie


Jul 23 '05 #1
3 1517
Astra wrote:
Hi All

Wonder if you can help me with the following calc, which I want to create to
check whether or not a user has entered a valid credit card expiry date:

1) I have retrieve a value from 2 x SELECTs. One value is the month in a 2
DIGIT form, eg 01, 02, 03, 04, etc, and the other is the year in a 4 DIGIT
form, ie 2004, 2005, 2006, 2007, etc.

2) My Maths for this was going to be that I do a calc on the figures
retrieved in the above point1 against figures retrieved for today's date, in
theory like the following:

[...]

If you create ISO8601 dates of the form yyyymm, you can compare them
dates using string concatenation of your variables.

If you need help with that, let us know.

Do not trust the date is set to on the client, check everything on the
server.

--
Rob.
Jul 23 '05 #2
RobG wrote:
Astra wrote:
Hi All

Wonder if you can help me with the following calc, which I want to
create to check whether or not a user has entered a valid credit card
expiry date:
[...]
If you create ISO8601 dates of the form yyyymm, you can compare them
dates using string concatenation of your variables.

If you need help with that, let us know.

Do not trust the date is set to on the client, check everything on the
server.


Yes. One way is to send a check date in the page sent to the client -
a meta tag will do the trick, but there are other methods. The check
date is then based on the server and not whatever the client may have
set.

Below is some sample code, note that I haven't done any validation of
the input since it is supposed to come from a select list that should
ensure it is OK. As always, check everything again on the server.

<html><head>
<title>untitled</title>
<meta name="checkdate" content="2004-11">
<script type="text/javascript">
function checkDate(y,m){
var expDate = y + m;
if(document.getElementsByTagName) {
var metaTags = document.getElementsByTagName('meta');
for (var i=0; i<metaTags.length; i++) {
if (metaTags[i].name == 'checkdate') {
var checkYear = metaTags[i].content.split('-')[0];
var checkMonth = metaTags[i].content.split('-')[1];
break;
}
}
var checkDate = checkYear + checkMonth;
if (expDate >= checkDate) {
alert('Card expiry date ' + y
+ '-' + m + ' is OK')
} else {
alert('Sorry, Card expiry date ' + y
+ '-' + m + ' has expired')
}
}
}
</script>
</head>
<body>
<form action="">
<input type="text" name="year" value="2005">Enter a year (yyyy)<br>
<input type="text" name="month" value="10">Enter a month (mm)<br>
<input type="button" value="Check date" onclick="
checkDate(this.form.year.value,this.form.month.val ue);
this.blur();
">&nbsp;
<input type="reset">
</body></html>

--
Fred
Jul 23 '05 #3
JRS: In article <41ab88d1$0$25766$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 30 Nov 2004 06:34:29, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :
Astra wrote:

Wonder if you can help me with the following calc, which I want to create to
check whether or not a user has entered a valid credit card expiry date:

1) I have retrieve a value from 2 x SELECTs. One value is the month in a 2
DIGIT form, eg 01, 02, 03, 04, etc, and the other is the year in a 4 DIGIT
form, ie 2004, 2005, 2006, 2007, etc.

2) My Maths for this was going to be that I do a calc on the figures
retrieved in the above point1 against figures retrieved for today's date, in
theory like the following:

[...]

If you create ISO8601 dates of the form yyyymm, you can compare them
dates using string concatenation of your variables.

If you need help with that, let us know.

Do not trust the date is set to on the client, check everything on the
server.


To get the client date as yyyymm, one can use

with (new Date()) S = String(getFullYear()*100+getMonth()+1)

or, short-term,

with (new Date()) S = String(getYear()%100*100+getMonth()+200001)
IMHO, whether or not to trust the client date depends on how much the
author cares whether the user screws up.

Given that a user can subvert a reply, anything that matters to the
author must be checked at the author's end.
There is a problem in validating credit card dates, which particularly
affects New Zealanders visiting Hawaii on the last date of validity, and
/vice versa/.
The OP's javascript engine seems to have Date methods not authorised by
ECMA-262 Edn 3.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: Garrett | last post by:
Hi all, I am trying to run calc from the command line using a Process. I am clearly missing something obvious here because the command line opens but the "Calc" arg never executes...code...
29
by: VirtualDev | last post by:
What is the future of C++?, and what is the C++0x? and is it really going to include a standard portable libraries for GUI, networking, embedded systems and so on?
1
by: sherifffruitfly | last post by:
Hi, I've got a checked list box, and a "go' button on the form. Each item in the checked list box is associated with a program (say notepad, calc, etc.). When the user clicks "go", every item...
21
by: mm | last post by:
(Yes, I konw whats an object is...) BTW. I did a translation of a pi callculation programm in C to Python. (Do it by your own... ;-) -------- Calc PI for 800 digs(?). (german: Stellen) ------...
16
by: Matthew Zhou | last post by:
I am a students learning programming, and want to do some software projects to practice myself. However, no one will only use one language to make all the tasks done. And every languages has its...
6
by: chrisstuart | last post by:
Hi I've got a table with the following MonthNr ColumnNr RowNr Column01 ...... Column12
7
by: sparks | last post by:
I am working on a database that has a lot of calculated values on the forms. These were never put into the tables. But were tied to unbound fields on the forms. Now 8000 records later they want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.