Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:49:37+00:00 2026-06-17T07:49:37+00:00

I have a date field on a form. The date in the date field

  • 0

I have a date field on a form. The date in the date field has to be after today’s date and not in the past. It also has to be within 30 days from today’s date. So if today is 15/01/2013, then the form can only accept any date within 30 days after the 15/02/2013, so the 14/04/2007 plus 30 days!

Can any please help with the correct Javascript code? I’m an amature and don’t have a clue on how to achieve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:49:39+00:00Added an answer on June 17, 2026 at 7:49 am

    I guess you need something like this: http://jsfiddle.net/hqNxW/1/

    And the code…

    JavaScript

    var output = document.getElementById('messageOutput');
    document.getElementById('validate').onclick = function () {
        var value = document.getElementById('date').value;
        if (!validateDate(value)) {
            notify('Invalid date format');
        } else {
            if (!validateDateRange(value)) {
                notify('The date should be after today but not more than 29 days!');
            } else {
                notify('Valid date');
            }
        }
    }
    
    function notify(msg) {
        output.innerHTML = msg;
    }
    
    function validateDate(date) {
        return (/^\d{2}-\d{2}-\d{4}$/).test(date);
    }
    
    function validateDateRange(inputDate) {
        var now = new Date(),
            after30Days = new Date().setDate(now.getDate() + 30)
            date = new Date(inputDate);
        return date > now && date < after30Days;
    }
    

    HTML

    <input type="text" id="date" /> <button id="validate">Validate</button>
    <div id="messageOutput">Enter a date in the following format: mm-dd-yyyy</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a start date and end date field. Both has seperate ajax calender
i am making a form that has a date field using textfield, i want
I have a form which has a date. I registered a customDateEditor for converting
serializeArray() does not pick up form fields that have been added after page load
I have a date input field in my jsp like this: <form:input name=inputDate id=inputDate
I have a Date of birth field in my admin form of my django
As basicly explained in the title I have a form with a date field.
I have a text field that uses jQuery UI Datapicker. It also has an
I have the following situation: a form field type date a validation pattern like
I have a form(TrimQuery) that has 2 editable date picker fields (Start_Date & End_Date)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.