Click to See Complete Forum and Search --> : How to validate month, day, year?


CalifNina
06-12-2003, 09:07 PM
I haven't a clue how to validate on any level. Am asking how to accomplish such a feat for the date (mm dd yyyy)?? ... am building a FORM that has input fields for credit card information ... in the BODY of the code within the FORM, I have the credit card date in three separate fields:

(1) The month is a drop-down/selection box with possible values of an empty selection ... or ... 01-12.
(2) The date is a separate input field limited to two characters. (ie., nn)
(3) The year is a separate input field limited to four characters. (ie., yyyy) Exp Month:
<SELECT NAME="creditCardExpMonth">
<OPTION>
<OPTION>01
<OPTION>02
<OPTION>03
<OPTION>04
<OPTION>05
<OPTION>06
<OPTION>07
<OPTION>08
<OPTION>09
<OPTION>10
<OPTION>11
<OPTION>12
</SELECT>

&nbsp;Exp Date:
<INPUT TYPE="text" VALUE="nn" NAME="creditCardExpDate" SIZE="2" MAXLENGTH="2">

&nbsp;Exp Year:
<INPUT TYPE="text" VALUE="yyyy" NAME="creditCardExpYear" SIZE="4" MAXLENGTH="4">First question: How do I validate the credit card expiration year?

Second question: How do I verify in a comparison with the current date - if the entire credit card expiration is valid (all three areas)?

Are these too complicated? Two-three separate routines to figure out? I have no idea what to do or how to start. Looking for direction, guidance, and code on how to do these Please. Thank You and pls bear with me on this, I am lost.

requestcode
06-12-2003, 10:01 PM
Are their credit cards that specify the day? Mine only have the month and year. I would also have a dropdown for the year instead of leaving it up to them to type it in. I would also leave the blank out for the month and let it default to 01. If you want to get real fancy you could probably determine the current year add how many years you want and then create the dropdown using javascript.

CalifNina
06-13-2003, 01:23 AM
requestcode thks for the reply... Yes, I've had both situations where the actual date is included and also been the other situation of just the month/year -- that's why I stuck in the date cuz I had seen it ... but I took your suggestions and improved by having the user select the year; versus typing it in -- and then removing the blank from the month selections so it defaults to 01.

The adjusted code is as follows ...

(1) The month is a drop-down/selection box with possible values of 01-12.
(2) The year is a drop-down/selection box with possible values of 2003-2010.&nbsp;Exp Month:
<SELECT NAME="creditCardExpMonth">
<OPTION>01
<OPTION>02
<OPTION>03
<OPTION>04
<OPTION>05
<OPTION>06
<OPTION>07
<OPTION>08
<OPTION>09
<OPTION>10
<OPTION>11
<OPTION>12
</SELECT>

&nbsp;Exp Year:
<SELECT NAME="creditCardExpYear">
<OPTION>2003
<OPTION>2004
<OPTION>2005
<OPTION>2006
<OPTION>2007
<OPTION>2008
<OPTION>2009
<OPTION>2010
</SELECT>So, my questions for help remain:

How do I validate the credit card expiration year?
How do I verify in a comparison with the current date - if the credit card expiration they select is valid?

havik
06-13-2003, 02:53 AM
Try this:
http://javascript.internet.com/forms/val-credit-card.html

Havik

CalifNina
06-13-2003, 03:05 AM
Havik, thks for the reply and advice. I just skimmed through it -- WOW that is heavy duty complicated code there. yikes and yup I did kind of guess it was not gonna be easy.

Won't just jump and say I can do this or will be able to incorporate into what I've got already, but I'll play around with it and see if I get anywhere.

It is an example and something to go by. Thank you.

havik
06-13-2003, 03:07 AM
Remember, if you need help integrating the new code, just post. :D

Havik

CalifNina
06-13-2003, 03:14 AM
definitely will do, thks... Give me a few days to sort it out and mess with the various sections -- then I may be back for help if I do not succeed ... :p :rolleyes: my fingers are crossed I can figure it out.

Charles
06-13-2003, 05:22 AM
Originally posted by CalifNina
WOW that is heavy duty complicated code there. yikes and yup I did kind of guess it was not gonna be easy. This simple script will let your users enter the date in one text field and in any of several formats.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
Date.prototype.toString = function () {return [this.getMonth() < 9 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1, this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getYear()].join(' ')}
// -->
</script>
<form action="">
<div>
<label><input type="text" onchange="this.value = new Date(this.value)">Expiration Date</label>
</div>
</form>

CalifNina
06-13-2003, 10:05 AM
Thks Charles, I'll take a look at this too!