Sponsored Ad

Friday, March 26, 2010

How to check for a Number in JavaScript | IsNumber()

this java script utility will help you to find that a given string is number or not. just pass a string in  this utility and it will return true or false.

 

How to call this method:

IsaNumber(‘123’)

result: true

IsaNumber(‘abc’)

result : false

 

 

function IsaNumber(strString)
{
   var strValidChars="0123456789";
   var strChar;
   var blnResult=true;
   if (strString.length==0) return false;
   for (var i=0;i<strString.length && blnResult==true;i++)
   {
      if (strValidChars.indexOf(strString.charAt(i))==-1)
      {
          blnResult = false;
      }
   }
   return blnResult;
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers