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

147
Vistas
How to insert a space after user types the slash character (/) inside a content editable input field?

From what I have seen so far here on stackoverflow, there are some recommendations about the String.replaceAll() function, or using javascript with the input ID. The code below will introduce a space after five characters, but I need it to add the space after the slash character is typed.

    document.getElementById('target').addEventListener('input', function (e) {
    var target = e.target, position = target.selectionEnd, length = target.value.length;
  
    target.value = target.value.replace(/\s/g, '').replace(/(\d{5})/g, '$1 ').trim();
    target.selectionEnd = position += ((target.value.charAt(position - 1) === ' ' && target.value.charAt(length - 1) === ' ' && length !== target.value.length) ? 1 : 0);
});

<label id="target" contenteditable="true" type="text"/>someText</label>

I appreciate any guidance.

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