www.webdeveloper.com
Results 1 to 2 of 2

Thread: Validate Date Range

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Validate Date Range

    I am new to Javascripting. I would like to validate a date field on my form that someone can not enter a future date or a date that is more than 90 days before the current date. I would think that I would start with the current date and check against the input date, but not sure how to write this.

  2. #2
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    588
    Try something like this:
    Code:
    InValue=document.forms[0].DateFieldName.value;
    IValue=new Date(InValue)*1;  // in miliseconds since 1-1-1970
    Now=new Date()*1;
    Now_90=Now-90*24*60*60*1000;  // minus 90 days in miliseconds
    if ((IValue > Now) || (IValue < Now_90)) {
     alert('Bad!');
    }

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