Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!