Reputation: 197
I have been trying to validate a text field for numeric with JavaScript. I had it as a type "number" but IE 9 doesn't do this. This is the code I used:
var c=document.getElementById("employee_count").value;
if (c<=0)
{
alert("Employee numbers must be filled out");
form1.employee_count.focus();
return false;
}
if (!is_int(c)) {
alert("Employee numbers must be numeric");
form1.employee_count.focus();
return false;
}
I first validated that there was some input and this worked but when I put in the code with !is_int and put an alphabetic character in to test, the whole form submitted without any further validation of fields. Can anyone spot what I am doing wrong? It is driving me crazy. If I omit the last if statement the subsequent code works correctly. Thanks in advance,
Geoff.
Upvotes: 0
Views: 391
Reputation: 46900
That is JavaScript, not PHP. In JavaScript you could check like
if (isNaN(c)) { //if c is not a number
Upvotes: 3