Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field value is a number

Status
Not open for further replies.

vasilek

Programmer
Jan 5, 2003
99
0
0
US
Hello. This was probably asked before, but it doesn't come up on the top of search results.

How to check if the value in the field is a number?


I would like to prohibit entering everything but numbers into quantity field.

Thank you.
 
Try this:
Code:
<script>
<!--
function KillLetters() {
   if (event.keyCode < 48 || event.keyCode > 57) {
       event.keyCode = 0;
   }
}
//-->
</script>

<input type="text" onkeyup="KillLetters()">
 
You can also try:

Code:
<script>
function onlyNum() {
  var Gm = document.form1;
  if(isNaN(Gm.field1.value)) {
    alert("Only numbers please");
    return false;
  }
}
</script>
...
...
<input type="text" name="field1" onBlur="return onlyNum();">

[sub]
____________________________________
Just Imagine.
[sub]
 

I would go with GUJUm0deL's solution, as Supra's will not let you enter valid numbers such as "1.5", "2.3", etc.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top