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

161
Views
Sólo números. Número de entrada en React

Estoy tratando de excluir menos y más de la entrada, pero sale mal:

 handleChange(event) { const value = event.target.value.replace(/\+|-/ig, ''); this.setState({financialGoal: value}); }

Procesar código de entrada:

 <input style={{width: '150px'}} type="number" value={this.state.financialGoal} onChange={this.handleChange}/>
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Traté de imitar su código y noté que hay un problema en React con <input type='number' /> . Para solucionarlo, consulte este ejemplo y pruébelo usted mismo: https://codepen.io/zvona/pen/WjpKJX?editors=0010

Debe definirlo como entrada normal (tipo = 'texto') con patrón solo para números:

 <input type="text" pattern="[0-9]*" onInput={this.handleChange.bind(this)} value={this.state.financialGoal} />

Y luego para comparar la validez de la entrada:

 const financialGoal = (evt.target.validity.valid) ? evt.target.value : this.state.financialGoal;

La mayor advertencia sobre este enfoque es cuando se trata de dispositivos móviles -> donde el teclado no está en formato numérico sino en formato alfabético normal.

over 4 years ago · Santiago Trujillo Report

0

Simplemente camino en React

 <input onKeyPress={(event) => { if (!/[0-9]/.test(event.key)) { event.preventDefault(); } }} />
over 4 years ago · Santiago Trujillo Report

0

una línea de código

 <input value={this.state.financialGoal} onChange={event => this.setState({financialGoal: event.target.value.replace(/\D/,'')})}/>
over 4 years ago · Santiago Trujillo Report
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!