dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: How to validate month, day, year?

  1. #1
    Join Date
    May 2003
    Location
    San Jose, CA., USA
    Posts
    64

    Question How to validate month, day, year?

    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.

  2. #2
    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.

  3. #3
    Join Date
    May 2003
    Location
    San Jose, CA., USA
    Posts
    64
    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?

  4. #4
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638

  5. #5
    Join Date
    May 2003
    Location
    San Jose, CA., USA
    Posts
    64
    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.

  6. #6
    Join Date
    Jan 2003
    Location
    Peg City
    Posts
    638
    Remember, if you need help integrating the new code, just post.

    Havik

  7. #7
    Join Date
    May 2003
    Location
    San Jose, CA., USA
    Posts
    64
    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 ... my fingers are crossed I can figure it out.

  8. #8
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    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>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  9. #9
    Join Date
    May 2003
    Location
    San Jose, CA., USA
    Posts
    64
    Thks Charles, I'll take a look at this too!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles