-1

I'm trying to figure out, that how to remove the double spaces which are placed in-between texts in the HTML Text field. [For example: Tom and Jerry - in here, after "Tom" there are two spaces are placed]. I need to remove or replace the double spaces and place a single space only while keying in the HTML text box. Any Help on this? ... Thanks

1 Answers1

2

You might add a keyup listener, which, when triggered, uses a regular expression to replace all double-spaces (or more) with single spaces:

const input = document.querySelector('input');
input.addEventListener('keyup', () => {
  input.value = input.value.replace(/  +/g, ' ');
});
<input>
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320