Chek Numeric Value in Java script

Validation for numeric value

<SCRIPT language="JavaScript">
  <!--

function IsNumeric(strString)
   //  check for valid numeric strings    
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

  // -->
</SCRIPT>

**********************************

<SCRIPT language="javascript type="text/javascript">

function NumbersOnly(e)
{
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode<48||unicode>57)
return false

}

</SCRIPT>
***************************************
U can use the below javascript:

function valInteger(obj)
{
var i,strVal,blnChange;
blnChange = false
strVal="";

for(i=0;i<(obj.value).length;i++)
{
switch(obj.value.charAt(i))
{
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":strVal=strVal+obj.value.charAt(i);
break;
default :blnChange = true;
break;
}
}    
if (blnChange)
{
obj.value=strVal;
}
}

Page ,for that textbox'a keyup give like this

onkeyup="return valInteger(this)"
************************************
By Anil pandey   Popularity  (2773 Views)