Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
Change value input onclick witch setTimeout

How can I remove special symbols (R$) when clicking the button, or simply remove if it exists?

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

I would like that when clicking on the button, it would also remove the symbol R$

I have so far

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 Respostas
Responde à pergunta

0

Just use the String.replace() method and then the String.trim() method to ensure there are no leading or trailing spaces left behind..

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 Relatório

0

Your regex for removing the special symbol is right, only error was of setTimeout & function declaration error.

I have fixed that code error.

Below snippet will work, but in function clean() it will wait for 1000ms because of setTimeout function.

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda