07.20.08

Is a variable a number

Posted in General Javascript | at 2:54 am by admin

Often we need to see whether a variable is a number. Here is the code:-

function IsNumeric(sText)
 
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
 
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 
}

Leave a Comment

You must be logged in to post a comment.