...

View Full Version : text field restriction



eranwein
01-29-2006, 12:00 AM
hi.

i've added this function to restrict inserted values to digits only by using:

onkeydown="return isFinite(parseInt(String.fromCharCode(event.keyCode)))

two problems:

1. i'm restricted only to digits and can't use delete , backspace or arrows.
2. the numbers on the right of the keybord dont work (the ones with Num Lock)

any ideas?

arnyinc
01-29-2006, 02:15 AM
I know this isn't exactly what you're asking, but how about this:



<html>
<head>
<script language="javascript">
function checkNum(object) {
object.value=object.value.replace(/\D*/g, "");
}
</script>
</head>

<body>
<input type="text" onkeyup="checkNum(this);">
</body>

</html>

konithomimo
01-29-2006, 03:04 AM
instead of what you have use this:

onkeyup="this.value=this.value.replace(/\D/,'')"

that will allow only numbers, as well as tabbing, the arrow keys, and backspacing. You can also use the key pad.

eranwein
01-29-2006, 03:21 AM
it's good.
is there a way to allow arrows also?

konithomimo
01-29-2006, 04:57 AM
The code I supplied does allow you to use the arrow keys.

Ancora
01-29-2006, 03:47 PM
eranwein:
Read your PMs.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum