isInteger Function



<input name="cmdCalc" type="button" onclick=document.getElementById("txtResult").value=isInteger(document.getElementById("txtInteger").value); value="Check" style="width: 59">


function isInteger (numericValue)
{
// set boolean to false if argument is empty or not a number
var allIntegerCharacters = !isEmpty(numericValue) && !isNaN(numericValue);

// if first character in number is a negative sign, skip it in the subsequent check
if (numericValue.charAt(0) == "-" ) lcv = 1;

var len = numericValue.length
while (lcv < len && allIntegerCharacters)
{
allIntegerCharacters = isDigit(numericValue.charAt(lcv));
lcv ++;
}

return allIntegerCharacters;
}

function isEmpty(str)
{
return ((str == null) || (str.length == 0));
}

function isDigit (char)
{
return ((char >= "0") && (char <= "9"));
}


demo