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

355
Vistas
React Native: How to enforce max length on input, including after decimal?

In my React Native app I'm using the <Input> component from Native Base which is based on the standard <TextInput> component. I want to enforce a max length of 5 digits regardless of whether there's a decimal point. So if the user just types 1's, the max would be 11111, or 111.11. The problem is that since the input is a string, it considers the decimal point a character, so it stops me after 111.1.

How can I achieve this?

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

0

You could create a function that transforms your number into a string, remove the point and measure the length, then call this function from your onChangeText:

let nrs = [11111, 1111.1, 111.11, 111111, 111.111]

function checkIfLessThenFiveDigits (nr){
 let str = nr.toString() // e.g. "11111", "111.11", "111111"
 let woPoint = str.replace('.', '') // e.g. "11111", "11111", "111111"
 let isValid = woPoint.length <= 5

 return isValid
}

for (var i of nrs)
 console.log(i + ' is ' + checkIfLessThenFiveDigits(i))

// onChangeText={checkIfLessThenFiveDigits}
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