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

130
Vistas
Regex for single digits and single digit with decimal only

I'm having a hard time coming up with the most suitable regex for my needs.

I want a regex that only validates numbers from 1-8, with or without a decimal point

1 // Valid
3 // Valid
8 // Valid

2.00 // Valid
4.45 // Valid
7.60 // Valid

9 // Invalid
10 // Invalid
9.00 // Invalid
50.40 // invalid

So far this is what I came up with, but ^([0-8]$\.?[0-8]*|\.[0-8]+) but this only accepts numbers from 1-8, and nothing with a decimal. Can someone kindly provide a suitable regex for this example?

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

0

I guess it would be better to limit regex to string parsing. My best approach would be to parse a valid number from the string and then convert it to number before doing any validation on its value as being < x

But if you really want to go via regex (and it will be hard to change in case) would be with something like:

^0*([0-7](\.\d+)?|8)$

It matches any number between 0 and 8 ... decimal point is allowed if followed by numbers and the highest valid number like that would be 7.999999999... followed by the next valid integer number being 8.

Trailing zeros are considered.

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