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

618
Vistas
Regex for if a number contains a decimal point, it must have a decimal

There is another question, which deals with a mandatory decimal place, in this case, it is optional, and only if there are decimals. I need to check to see if a number is valid in a numeric input by comparing it to my regex on paste and keyed in. The number can contain up to 9 numbers, and if it has a decimal point, up to 6 decimal places.

For example:

123456789.123456

is a valid number, but

1234567890.1234567

or

1234567890.

is not valid. My regex thus far is:

/^(\d{0,9})(\.{0,1}\d{0,6})*$/

..but it still allows a decimal place without decimals.

RegExr link

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

0

Use

^\d{0,9}(?:\.\d{1,6})?$

See regex proof.

EXPLANATION

--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  \d{0,9}                  digits (0-9) (between 0 and 9 times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (optional
                           (matching the most amount possible)):
--------------------------------------------------------------------------------
    \.                       '.'
--------------------------------------------------------------------------------
    \d{1,6}                  digits (0-9) (between 1 and 6 times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
  )?                       end of grouping
--------------------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
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