hi..
I would like to validate users input into a form, allowing only the number keys (eg no negatives or decimals)
I have found some basic code which traps out numbers using isNaN, but this allows -ve and decimals. could someone help me extend this to allow only +ve integers??? I have tried using this function on keypress, onkeyup etc but isnt quite right.
I would like to validate users input into a form, allowing only the number keys (eg no negatives or decimals)
I have found some basic code which traps out numbers using isNaN, but this allows -ve and decimals. could someone help me extend this to allow only +ve integers??? I have tried using this function on keypress, onkeyup etc but isnt quite right.
Code:
<script language="javascript">
<!--
function validate(txtbox)
{
if (isNaN(txtbox.value) || txtbox.value=="") {
alert("Invalid Entry!");
txtbox.focus();
} else {
alert("Do whatever you would do for a proper entry!");
}
}
//-->
</script>
<form>
<input type="text" name="entry" onchange="validate(this.form.entry);">
<input type="button">
</form>