By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,334 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Re: field value AFTER numeric validation

P: n/a
SAM
Evertjan. a écrit :
>
Try, IE7 & FF2 tested:
Not working on my Mac :-(
(FF2, Safari2)

keys with keyCode 48 to 57 need the shiftkey in addition to get a number
from alpha keyboard
- works with Safari
- not with F2 who return a keyCode for the shift's key
(not in the allowed plage :-( )

keys from numeric keyboard aren't more allowed ... ! :-(

But I can tape : @ & $ €

And no more backspace ... tab ... enter ... :-(
<input type="text" onkeypress="return IsNumeric(event);">

<script type='text/javascript'>
function IsNumeric(e) {
var c = e.keyCode? e.keyCode : e.charCode
if (c >= 48 && c <= 57)
return true;
alert('Only Numbers, please.');
return false;
};
</script>

This will not prevent pasting alpha strings!!!!!
Only if you use menu (and not use keyboard shortcuts)

--
sm
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SAM wrote on 31 mei 2008 in comp.lang.javascript:
Evertjan. a écrit :
>>
Try, IE7 & FF2 tested:

Not working on my Mac :-(
(FF2, Safari2)

keys with keyCode 48 to 57 need the shiftkey in addition to get a
number
from alpha keyboard
- works with Safari
- not with F2 who return a keyCode for the shift's key
(not in the allowed plage :-( )

keys from numeric keyboard aren't more allowed ... ! :-(

But I can tape : @ & $ €

And no more backspace ... tab ... enter ... :-(
><input type="text" onkeypress="return IsNumeric(event);">

<script type='text/javascript'>
function IsNumeric(e) {
var c = e.keyCode? e.keyCode : e.charCode
if (c >= 48 && c <= 57)
return true;
alert('Only Numbers, please.');
return false;
};
</script>

This will not prevent pasting alpha strings!!!!!

Only if you use menu (and not use keyboard shortcuts)
It is a bad idea anyway, as it interferes with typing habits.

Better test the string onsubmit.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.