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

145
Vistas
Regex for maximum 4 digit with dot, accept only number and separate with dot every thousand

I have a problem to convert input in HTML to specific criteria :

  • Maximum 4 digit with dot (ex : 5.100)
  • Only accept number
  • Separate with dot if thousand

I am able to achieve the last two with this :

value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ".");

How to add the first criteria ?

And seems like my regex is too long, a shorter one would be great.

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

0

Remove all but first four digits:

const value = `123456`
console.log(
   value.replace(/\D/g, "").replace(/^(\d{4})\d+/, '$1').replace(/\B(?=(\d{3})+(?!\d))/g, ".")
)

about 4 years ago · Juan Pablo Isaza Denunciar

0

I would use a mask for the input,

("#id").inputmask({
                mask: "9.999", 
                placeholder: "",
                separator: "", 
               });

Then to check the value,

value.replace('.',''); 

and with a regular expression to verify that it is true that they are only digits and at most 4.

let regex_aux = /^\d{4}/;
 if(regex_aux.test(value)){
        //do something
    }
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