0

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.

2
  • 8
    Are you sure that that's PHP? It looks a little Javascript-y from here. Commented Jun 14, 2013 at 15:44
  • you are so right. How daft? Commented Jun 14, 2013 at 15:54

1 Answer 1

3

That is JavaScript, not PHP. In JavaScript you could check like

if (isNaN(c)) {     //if c is not a number
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.