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

295
Views
Cómo hacer que la entrada Vue js vuetify permita solo 3 dígitos antes del decimal y 2 dígitos después del decimal

Necesito establecer un límite para el número de entrada total en 3. Por ejemplo, el usuario puede ingresar 333 , 123 , etc. Sin embargo, si usan el punto decimal, podrán ingresar 2 dígitos después del punto decimal. Entonces, estas entradas son válidas:

123

123.33

Aquí está el código que he escrito hasta ahora:

 isNumber (event, message) { // preventing multiple decimal if (!/\d/.test(event.key) && (event.key !== '.' || /\./.test(message))) { return event.preventDefault() } // limiting three numbers before decimal point and two digits after decimal point if (/^(\d{0,3}\.)?\d{1,2}$/.test(message)) return event.preventDefault() }

Pero, esta expresión regular, /^(\d{0,3}\.)?\d{1,2}$/ no funciona para mi caso

Demostración de CodePen

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Puede considerar usar una entrada de número ( <input type="number"> ), con una propiedad max para controlar la cantidad de dígitos y un pequeño controlador de teclado para controlar el valor.

 document.addEventListener('keyup', handle); function handle(evt) { if (evt.target.id === `num`) { if (evt.key === `Backspace`) { return true; } const [number, int] = [parseFloat(evt.target.value), parseInt(evt.target.value)]; evt.target.value = number > evt.target.max ? evt.target.max : number === int ? int : number.toFixed(2); document.querySelector(`#value`).textContent = `current value: ${evt.target.value}`; } }
 <input id="num" type="number" step="0.1" max="999.99"> <div id="value"></div>

about 4 years ago · Santiago Trujillo Report

0

Puede usar la siguiente expresión regular:

 ^\d{0,3}(?:\.\d{1,2})?$

Lo que hay que recordar es hacer la parte fraccionaria, incluido el . , opcional.

Manifestación

about 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!