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

212
Views
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 answers
Answer question

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 Report

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