Only three or n decimal places are allowed

Rajni.Shekhar
Posted by Rajni.Shekhar under JavaScript category on | Points: 40 | Views : 1345
function checkDecimal(ID)
{
var strString = document.getElementById(ID).value;
var currIndex=strString.indexOf('.');
if(currIndex!=-1)
if(currIndex+4 <strString.length) // 4=n+1 number exmaple here is 3 code is for 3 decimal points so i used check for 4
{
alert("Only 3 decimal places are allowed to enter.");
document.getElementById(ID).focus();
return false;
}
}

Comments or Responses

Login to post response