troubleshooting Question

JavaScript username validation

Avatar of darkpegasus5
darkpegasus5 asked on
JavaScript
18 Comments2 Solutions1927 ViewsLast Modified:
I have a form called form1 that has an input called employeeID. What would I put in a validate_form() method to make sure that 1. The field is not empty and 2. the field is a number. Here is what I have tried but it hasn't worked:

<form ... onsubmit="return IsNumber(document.form1.employeeID);">

function IsNumber(sText)
      {

         var ValidChars = "0123456789";
         var IsNumber=true;
         var Char;
         if(sText=="") {alert("Username should not be empty");return false}
         for (i = 0; i < sText.length && IsNumber == true; i++)
         {
            Char = sText.charAt(i);
            if(ValidChars.indexOf(Char) == -1)
            {
             IsNumber = false;
            }
         }
         if(!IsNumber)
            alert("EmployeeID must be a number")
         return IsNumber;
      }
ASKER CERTIFIED SOLUTION
NeoTeq

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros