My Thoughts & Views

IsNumeric Javascript Validation for Numerals

Posted on: June 16, 2007

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.”)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: