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

141
Vistas
Regex pattern matching for decimal

I need to match a pattern for validation . I want to match a decimal number where numeric part has upto 7 digits and after decimal has upto 9 numbers. Valid patterns are :

1.8
1234567.123456789
.8
0.7
12.78

I tried to use "^[0-9]{7}.[0-9]{9}$" but it is not working as expected

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

0

The repetition argument specified in the curly brackets is for matching an exact number of matches of the previous token. Your regex is trying to match EXACTLY 7 digits ({7}), followed by EXACTLY 9 digits ({9}). You're also using the dot wildcard to match the decimal point, which you ought to be escaping with a slash (\.) as you intend to match the literal character dot rather than any character.

From the look of your examples, it seems you want to match between 0 and 7 digits before the decimal point, and then between 1 and 9 after. A suitable regex for this would be:

^[0-9]{0,7}\.[0-9]{1,9}$

Notice that I too am using repetition, but I am providing two arguments. The first argument is the minimum number of matches of the previous token, and the second argument is the maximum. This way we can be very explicit about the exact number of repetitions we expect.

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