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

213
Visualizações
Strip spaces and make string lowercase with Javascript

I have the following script that duplicates the content I'm entering in one field into another.

DEMO: https://jsfiddle.net/wk3nmc76/

I was wondering if it's possible I could change the 2nd field to strip spaces & make the value lowercase?

<p><input type="text" name="full_name" id="full_name" placeholder="Full Name"/></p>
<p><input type="text" name="last_name" id="last_name"></p>
$('#full_name').keyup(function(){
   $('#last_name').val(this.value);
});
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

To achieve this you can use a combination of toLowerCase() and a regular expression to remove all the spaces. Try this:

$('#full_name').keyup(function() {
  $('#last_name').val(this.value.toLowerCase().replace(/\s/g, ''));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
  <input type="text" name="full_name" id="full_name" placeholder="Full Name" />
</p>

<p>
  <input type="text" name="last_name" id="last_name">
</p>

about 4 years ago · Santiago Trujillo Relatório

0

$('#full_name').keyup(function(){
   $val = $(this).val()
   stripped_val = $val.replace(' ', '');
   lowercase_stripped_val = stripped_val.toLowerCase();
   $('#last_name').val(lowercase_stripped_val);
});

Or, in short:

$('#full_name').keyup(function(){
       $val = $(this).val()
       modified_val = $val.replace(' ', '').toLowerCase();
       $('#last_name').val(modified_val);
});
about 4 years ago · Santiago Trujillo 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