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

99
Vistas
JS/HTML Date picker enforce rule to ensure input is today

When creating a date picker, I have it set to only allow today onwards. which works... But it appears that the user can then tab into the field and change the date to "before" today. Is there a way to enforce the "must be today or future date" rule?

Here is my example;

var today = new Date();
var d = today.getDate();
var m = today.getMonth() + 1;
var y = today.getFullYear();
if (d < 10) {
  d = '0' + d
}
if (m < 10) {
  m = '0' + m
}

today = y + '-' + m + '-' + d;
document.getElementById("datePicker").setAttribute("min", today);
<input id="datePicker" type='date' >

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

use EventListener to listen and set the value of your input to today date when entered value is lower than today

    var today = new Date();
    var d = today.getDate();
    var m = today.getMonth() + 1;
    var y = today.getFullYear();
    if (d < 10) {
      d = '0' + d
    }
    if (m < 10) {
      m = '0' + m
    }

    today = y + '-' + m + '-' + d;
    const input = document.getElementById("datePicker")
    input.setAttribute("min", today);

    input.addEventListener('change', (event) => {
      const d1 = new Date(today);
      const d2 = new Date(event.target.value);
      if(d1.getTime() > d2.getTime()){
        event.target.value = today
      }
    });
<input id="datePicker" type='date'>

about 4 years ago · Juan Pablo Isaza Denunciar
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