Forcing Numbers to be entered into a text box.
I have a textbox called txtCapacity.
I would like this to be limited to 3 numerical chars...ie number range from 0 to 999.
I can use a RegularExpressionValidator control and set it's ValidationExpression to \d{3}.
However, I would prefer it if I wasn't allowed to enter the word "Woof" at all, as using the above it only traps this on postback.
I have the following JS:
VB Code:
var phone = "()- 0123456789";
var numb = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
function res(t,v){
var w = "";
for (i=0; i < t.value.length; i++) {
x = t.value.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
t.value = w;
}
Then you add:
Code:
onkeyup="res(this,phone);"
This can be found on:
http://www.felgall.com/jstip44.htm
Now what would others do?
Woof
Re: Forcing Numbers to be entered into a text box.
Maybe something like:
[code]
if (! n.NaN)
if ((n >=0) && (n <= 99))
alert('number 0 <= n <= 999');
[/Highlight]