Validation for Numbers, Period and Percentage

Lakhangarg
Posted by Lakhangarg under JavaScript category on | Views : 4124
function NumericValidation(page)
{

var keyvalue=0;
if(navigator.appName=='Microsoft Internet Explorer')
{
keyvalue=event.keyCode;
}
else
{
keyvalue=page.which;
}
if((keyvalue >= 48 && keyvalue <= 57 )||(keyvalue == 46 )||(keyvalue == 37 )|| (keyvalue == 13))
{
return true;
}
else
{
alert("Only Numbers, Period and Percentage Symbols are allowed");
return false;
}
}


Call the above function on key press event of text box. like: onKeyPress="return NumericValidation(event);"

Comments or Responses

Login to post response