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

240
Views
Cambiar entrada de valor onclick bruja setTimeout

¿Cómo puedo eliminar los símbolos especiales (R$) al hacer clic en el botón, o simplemente eliminarlos si existen?

 setTimeout(function clean() { var input = document.getElementById('value') input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,'') },3000)

Me gustaría que al hacer clic en el botón, también quitara el símbolo R$

tengo hasta ahora

 setTimeout(function clean() { var input = document.getElementById('value') onclick = input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,'') }, 2000)
 <input id="value" name="item_valor" value="R$ 14,99" > remover simbolo pagseguro <br> <button class="" onclick="clean()">clean</button>

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Simplemente use el método String.replace() y luego el método String.trim() para asegurarse de que no queden espacios al principio o al final.

 const input = document.getElementById("value"); document.querySelector("button").addEventListener("click", function(){ input.value = input.value.replace("R$","").trim(); });
 <input id="value" name="item_valor" value="R$ 14,99" > remover simbolo pagseguro <br> <button>clean</button>

about 4 years ago · Santiago Gelvez Report

0

Su expresión regular para eliminar el símbolo especial es correcta, solo el error fue setTimeout y error de declaración de función.

He arreglado ese error de código.

El siguiente fragmento funcionará, pero en la función clean() esperará 1000 ms debido a la función setTimeout.

 function clean() { setTimeout(()=>{ var input = document.getElementById('value') onclick = input.value = input.value.replace(/[!$(){}[\]:;R<+?\\>]/g,''); input.value = input.value.trim(); }, 1000) // code inside setTimeout function will wait 1000ms to execute }
 <input id="value" name="item_valor" value="R$ 14,99" > remover simbolo pagseguro <br> <button class="" onclick="clean()">clean</button>

about 4 years ago · Santiago Gelvez 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!