Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda