Phurinat Puekkham
Phurinat Puekkham

Reputation: 68

Disable space in textbox (both typing spacebar and copy whitespace from other)

for prevent typing space code look like this (Javascript)

function RestrictSpace() {
  if (event.keyCode == 32) {
    return false;
  }
}

but it can't prevent paste whitespace how to fix it? thank you.

Upvotes: 0

Views: 318

Answers (1)

Edison Augusthy
Edison Augusthy

Reputation: 1573

HTML

<input type="text"onchange="myFunction(event)">

JS

 function myFunction(event) {
    console.log(event.target.value)
       event.target.value = event.target.value.replace(/\s/g, "");
    }

Upvotes: 3

Related Questions