• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

218
Vistas
react input field show the input althogh the user input is not legal, the value suppose to be numeric and the state doesnt change until it is numeric

my input field is showing letters it recieved as inputs althogh its state is not updated due to the test i have at the onchange event. for example: input field="dldld" and the state will be "".

my onchange function:

const handleChangeAdRentContent = (e) => {
    const re = /^[0-9\b]+$/;
    if (e.target.min) {
      if (e.target.value === "" || re.test(e.target.value)) {
        const name = e.target.name;
        const value = e.target.value;
        setInputAdConentRent({ ...inputAdConentRent, [name]: value });
      
        return;
      } else {
        return;
      }
    }
  };

this is the input field:

 <label
              key={masters[index].name + masters[index].adID}
              className={notdisplayRent}
            >
              <span>{masters[index].free_text}</span>
              <input
                type="text"
                name={masters[index].name}
                min={masters[index].min_value}
                max={masters[index].max_value}
                id={masters[index].name}
                required={masters[index].required}
                value={inputAdConentRent.name}
                onChange={handleChangeAdRentContent}
              />
            </label>

this is the input it consitst of an object of many inputs controlled by [key,value]

const [inputAdConentRent, setInputAdConentRent] = useState({});

thank you very much

about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda