www.webdeveloper.com
Results 1 to 3 of 3

Thread: Super Simple Validation

  1. #1
    Join Date
    Oct 2003
    Posts
    3

    Super Simple Validation

    Hi folks,

    I am a newbie to JavaScirpt and I want to do some simple validation. The key is that I want to validate that a month and a year field aren't less than the current month and year. I know that this is blatently incorrect, but I wanted to get an idea from some experts that will point me in the right direction.

    Thanks in advanced for your help.

    -Tim

    function checkccdate() {
    var month = new Date.getMonth()
    var year = new Date.getYear()
    var yesdate = month && year

    var formmonth = document.validator.cc_month.value
    var formyear = document.validator.cc_year.value
    var formdate = formmonth && formyear

    if (yesdate < formdate){
    alert ("I am sorry your Credit Card Expiration Date is invalid");
    }
    else (
    alert("Everything looks great!...your application has been submitted")
    )
    }

    By the way, here are the two fields from the form. (I numbered month 0 - 11 because of the getMonth thingy.

    <select name="cc_month">
    <option value="0" selected>Jan</option>
    <option value="1">Feb</option>
    <option value="2">Mar</option>
    <option value="3">Apr</option>
    <option value="4">May</option>
    <option value="5">Jun</option>
    <option value="6">Jul</option>
    <option value="7">Aug</option>
    <option value="8">Sep</option>
    <option value="9">Oct</option>
    <option value="10">Nov</option>
    <option value="11">Dec</option>
    </select>

    <select name="cc_year">
    <option value="2003" selected>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>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    </select>

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    <!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">
    <title>Example</title>

    <style type="text/css">
    <!--
    fieldset {float:left; padding:1ex}
    label {display:block; float:left; margin:0 1ex}
    select {display:block}
    button {clear:left}
    -->
    </style>

    <script type="text/javascript">
    <!--
    function verify (form) {
    if (new Date(form.year.value, form.month.value) < new Date()) {alert ('That would appear to be an invalid date.'); return false}
    }
    // -->
    </script>

    <form action="" onsubmit="return verify(this)">
    <div>
    <fieldset>
    <legend>Date</legend>
    <label>Month
    <select name="month">
    <option value="0" selected>Jan</option>
    <option value="1">Feb</option>
    <option value="2">Mar</option>
    <option value="3">Apr</option>
    <option value="4">May</option>
    <option value="5">Jun</option>
    <option value="6">Jul</option>
    <option value="7">Aug</option>
    <option value="8">Sep</option>
    <option value="9">Oct</option>
    <option value="10">Nov</option>
    <option value="11">Dec</option>
    </select></label>

    <label>Year
    <select name="year">
    <option value="2003" selected>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>
    <option value="2011">2011</option>
    <option value="2012">2012</option>
    <option value="2013">2013</option>
    </select></label>
    </fieldset>
    <button type="submit">Submit</button>
    </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

  3. #3
    Join Date
    Oct 2003
    Posts
    3
    That's the ticket.

    Thanks for your help.

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