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

146
Vistas
How do I leave a fixed value in a mask with regex?

I have a time mask, it accepts +1000h, but I wanted to set:00 after the hours

    return varTemp
      .replace(/\D/g, "")
      .replace(/(\d{2,4})(\d{2}$)/, "$1:$2")
  };

In this mask, : stays between hours and minutes. But I wanted to leave :00 fixed, without the minutes.


const maskHours = (value) => {
  return (
    value
      .replace(/\D/g, "")
      .replace(/(\d{2})/, "$1:00")
  );
};

In this mask, the value :00 is fixed, but the result is not good.

Thanks to whoever helps me!

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

0

Use

const maskHours = (value) => {
  return (
    value
      .replace(/\D/g, "")
      .replace(/^(\d{2,4})\d+/, "$1:00")
  );
};

EXPLANATION

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \d{2,4}                  digits (0-9) (between 2 and 4 times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  \d+                      digits (0-9) (1 or more times (matching
                           the most amount possible))
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