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

122
Views
Solo permite 1 coma y 2 decimales después

Tengo un código que me permite emparejar cosas como solo retroceso de dígitos. ¿Cómo puedo cambiar la expresión regular que permitirá presionar "enter" y permite solo 1 coma y después de la coma un máximo de 2 números?

 $("[name=price]").keydown(function(e){ if(e.keyCode == 110 || e.keyCode == 190) { e.preventDefault(); $(this).val($(this).val() + ','); } if (/\d|,+|[b]+|-+/i.test(e.key) ){ }else{return false } })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Aquí hay una versión un poco detallada. Esto acepta teclas de flecha, tabulador, enter, modificadores, etc.

 $("[name=price]").keydown(function(e) { if (e.keyCode == 110 || e.keyCode == 190 || e.keyCode == 188) { if ($(this).val().indexOf(',') > -1) { return false; } else { e.preventDefault(); $(this).val($(this).val() + ','); } } else if (e.keyCode < 47) { } else if (/\d|,+|-+/i.test(e.key)) { if ($(this).val().indexOf(',') > -1) { if ($(this).val().substr($(this).val().indexOf(',') + 1).length >= 2) { return false; } } } else { return false } })
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input name="price" /> <input name="price" /> <input name="price" />

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!