SHSHSHSHS
SHSHSHSHS

Reputation: 1

BLOCKING the input of numbers in the textarea/textbox

  <textarea rows="4" cols="20" onkeyup="this.value=this.value.replace([0-9], '')">
  </textarea>

this is my codes now I need to block the input of numbers zero to nine any idea on what to change in my codes

as much as possible I want to insert the code inside the < ....... >

Upvotes: 0

Views: 790

Answers (2)

Trojan
Trojan

Reputation: 2254

Use a regex. This shows the number, then deletes it. Fiddle

<textarea rows="4" cols="20" onkeyup="this.value=this.value.replace(/\d+/g, '')"></textarea>

Cleaner method: use onkeydown and return false based on keyCode. Fiddle with onkeydown

<textarea rows="4" cols="20" onkeydown="if((event.keyCode>47&&event.keyCode<58)||(event.keyCode>95&&event.keyCode<106))return false"></textarea>

Note: you have to handle the top row of numbers as well as the keypad in this case, hence the two sets of conditions.

Upvotes: 2

Ishan Jain
Ishan Jain

Reputation: 8171

You can also use this code :

<textarea rows="4" cols="20" onkeyup="this.value=this.value.replace(/[0-9]/g, '')"></textarea>

Try in Fiddel

Upvotes: 0

Related Questions