Saturday, June 16, 2007

IsNumeric Javascript Validation for Numerals

Inside u r Head Tag in HTML Page u insert the following code

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;
}

And to check whether the input box has numerals or not use follwing code

if(document.frmReg.MNumber.value=="")
alert("Enter Mobile Number.")
else if(IsNumeric(document.frmReg.MNumber.value)==false)
alert("Enter Only 10 Digit Mobile Number.")

No comments: