Javascript Code RegExp to Allow Single Space Between Words
Javascript RegExp Code to Allow Numbers, Upper and Lower Case Letters and a Single Space Between Words /(\s{2,})|[^a-zA-Z0-9']/g
Home
Short:
// allow upper/lower case letters, numbers, single space between words const regex = new RegExp(/(\s{2,})|[^a-zA-Z0-9']/g); // get handle to your input/text element you want // to only allow single space between words const inp = document.querySelector("#idOfInputElement"); inp.oninput =()=>{ inp.value = inp.value.replace(regex, " "); }
source code home