rebirth1078 rebirth1078 - 9 months ago 24
HTML Question

How do I remove space between characters for my text input field

I created an input that will let users created a username.

I to make sure there is no spaces between characters in the input field like:

username1


instead of:

username 1

aje aje
Answer Source

Use split() and join()

$(function() {
  $("input").on("keyup", function() {
    $(this).val($(this).val().split(" ").join(""));
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text"/>