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

475
Vistas
Regex for decimal and comma formatted number

I have a regex:

const reg = /^-?[0-9]*\.?[0-9]*$/;

Which checks for numbers with decimal places but I want to match commas too. It should match given below number comma should be before three digits, for example:

'12.00000'
'112.00000'
'1,123.00000'
'12,123.00000'
'123,123.00000'

To match decimal numbers:

const reg1 = /^-?[0-9]*\.?[0-9]*$/

To match commas:

const reg2 = /^\d{1,3}(?:,\d{3})*$/

I tried to combine both and tried to match:

  const reg1= new RegExp(/^-?[0-9]*\.?[0-9]*$/);
  const reg2= new RegExp(/^\d{1,3}(?:,\d{3})*$/);
  const finalReg = new RegExp(reg1.source + '|' + reg2.source);

But It does not match the number with commas and decimal, Is there any other way? Please advice.

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