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

255
Views
Deshabilitar el espacio como primer carácter en el campo de entrada no funciona en Chrome Android/App

Tengo este código que básicamente deshabilita agregar un espacio vacío dentro de un campo de entrada, sin embargo, no parece funcionar en Chrome Mobile/App/Android.

¿Alguien tiene alguna solución?

 <script> document.getElementById('firstname').addEventListener('keydown', function(evt){ if (this.value.length === 0 && evt.which === 32) evt.preventDefault(); }); </script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Según https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent , KeyboardEvent.which está obsoleto. Utilice KeyboardEvent.key en su lugar.

Consulte también la lista de códigos clave .

 document.getElementById('firstname').addEventListener('keydown', function(evt){ if (this.value.length === 0 && evt.key === " ") evt.preventDefault(); });
 <input id="firstname">

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar KeyboardEvent.code en su lugar

 document.getElementById('firstname').addEventListener('keydown', function(evt){ if (this.value.length === 0 && evt.code === 'Space') evt.preventDefault(); });
 <input id="firstname">

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!