Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to check out numeric values in js file? I am not able to enter -4,-5 etc for amount field(i mean negative values). My js function as follows:
C#
function IsIntegerFloatDot(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   var Count=0;

   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (Char == '.' )
        {
            Count++;
        }
      if (ValidChars.indexOf(Char) == -1 || Count > 1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
and function called as 
if(trimSpaces(document.getElementById("txtAmount").value) != "")
	    {
            var txtTotalEmployees = document.getElementById("txtAmount")
	        if (IsIntegerFloatDot(txtTotalEmployees.value)==false)
	        {
	            alert("Amount should be numeric values.");
		        txtTotalEmployees.focus();
		        return false;
	        }
	    }

   }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900