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

90
Views
Regla de aplicación del selector de fecha JS/HTML para garantizar que la entrada sea hoy

Al crear un selector de fecha, lo configuré para permitir solo hoy en adelante. que funciona... Pero parece que el usuario puede luego tabular en el campo y cambiar la fecha a "antes" de hoy. ¿Hay alguna manera de hacer cumplir la regla "debe ser hoy o en una fecha futura"?

Aquí está mi ejemplo;

 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 answers
Answer question

0

use EventListener para escuchar y establecer el valor de su entrada a la fecha de hoy cuando el valor ingresado es más bajo que hoy

 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 Report
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!