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

112
Views
El controlador de entrada [tipo = "número"] no funciona correctamente [Formik, RegExp]

Tengo una entrada que no puede tener más de 2 decimales. También tengo validación, que no funciona correctamente para números con muchos ceros.

Comportamiento esperado

Comportamiento inesperado

 export default function App() { const isValidAmount = (amount) => /^$|^\d+\.?\d{0,2}$/.test(String(amount)); return ( <div> <Formik initialValues={{ decimalNumber: "" }}> {({ handleChange }) => ( <Field className="input" type="number" name="decimalNumber" placeholder="Decimal Number" component={TextField} InputProps={{ onChange: (e) => { if (!isValidAmount(e.target.value)) return; handleChange(e); } }} /> )} </Formik> </div> ); }

código aquí

¿Puede por favor explicar: ¿Qué está pasando?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Utilice el atributo de step HTML para limitar los números permitidos. En este caso, desea limitar a centésimas:

 <Field /* ... */ step="0.01" />
about 4 years ago · Juan Pablo Isaza 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!