Possible Duplicate:
Validate that a string is a positive integer
So I want to check a form field if it's empty and to allow it to has only positive numeric numbers, no spaces or letters. So far I succeed the first part to check if the field is empty with the following code:
function validate(form) {
var elements = form.elements;
if (form.qty.value == "") {
alert("Please enter the field");
document.forms[0].qty.focus()
document.forms[0].qty.select()
return false;
}
return true;
}
Somewhere in the form:
<form action="addtocart.php" method ="post" onsubmit="return validate(this);" />
...
But now I want to allow only numbers as well as to check if the field is empty. I have found some scripts but I don't know how to merge the code into one valid script.