Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
how to check date entered by user in javascript

I want to create a function that takes as parameter the id of my input tag and checks the following cases: 1 - The date entered must be in the future (The date entered cannot be in the past) 2 - The date entered must not be greater than 6 months

this is my code

<body>
<h1>Check user date value</h1>
  a: <input type="date" name="dateResName" id="dateResId" required/>
  <input type ="button" value="Check Date User" onclick= "checkUserDate(document.getElementById('dateResId').value);" >

<script>
  function checkUserDate(dtUser) {
    var  today = new Date();
    var d = new Date(dtUser);
    var m = d.getMonth();
    var sixMonthAfterToday = new Date(now).setMonth(now.getMonth() + 6);
    var dtUserSixMonthAfter = d.setMonth(d.getMonth() + 6);
    if(dtUserSixMonthAfter > sixMonthAfterToday) {
    alert("The date entered must not be greater than 6 months");
    }
    
    if(true) {
    alert("The date entered cannot be in the past");
    }
  }
</script>
</body>

how can I check if the date cannot be in the past and not six month greater it ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!