how we can restrict a character to type in a text box.
A:
HTML is markup language, to achieve what you are looking for you will need to use javascript. Also you might try googling.
Darin Dimitrov
2010-06-17 07:12:54
+1
A:
If you have the text box then you have to handle the onkeypress
event
<input type='text' onkeypress='keypresshandler(event)' />
You can use the following function to restrict the users
function keypresshandler(event)
{
var charCode = event.keyCode;
//Non-numeric character range
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
}
Multiplexer
2010-06-17 07:13:42
We do it like this :)
Znarkus
2010-06-17 07:42:23
+3
A:
You can do this via javascript (so if javascript is off, you won't be able to restrict it)
<input type="text" onkeyup="this.value = this.value.replace(/[^a-z]/, '')" />
This will restrict it to only a-z characters. Checkout regular expressions to see what you can do
Ben Rowe
2010-06-17 07:14:48
Remember that this code only executes on the client side. The server script must be prepared to handle **any** input and reject invalid characters.
In silico
2010-06-17 07:17:27