Maxlength for decimal field on textbox
set maxlegth=16 for 13 digit + 1 .(point) + 2 fraction digit
MaxLength="16" onblur="fnDecMax(this.id,this.getAttribute('MaxLength'));"
javascript function
----------------------
function fnDecMax(id,maxLength)
{
theValue = document.getElementById(id).value;
maxLength = maxLength -1;
rx = /[^0-9.]/;
if(rx.test(theValue))
{
alert("The field can only contain numbers");
return;
}
if(theValue.indexOf(".") != -1)
{
theValue = theValue.substring(0,(theValue.indexOf(".") + 3));
}
lnt = theValue.length;
if(lnt > maxLength )
{
if(theValue.indexOf(".") == -1) {
theValue = theValue.substring(0,maxLength);
}
else
{
theValue = theValue.substring(0,(maxLength+1));
}
lnt = theValue.length;
}
if(lnt > (maxLength-2) && theValue.indexOf(".") == -1)
{
first = theValue.substring(0,(maxLength-2));
second = theValue.substring((maxLength-2));
theValue = first + "." + second;
}
document.getElementById(id).value= theValue;
}
set maxlegth=16 for 13 digit + 1 .(point) + 2 fraction digit
MaxLength="16" onblur="fnDecMax(this.id,this.getAttribute('MaxLength'));"
javascript function
----------------------
function fnDecMax(id,maxLength)
{
theValue = document.getElementById(id).value;
maxLength = maxLength -1;
rx = /[^0-9.]/;
if(rx.test(theValue))
{
alert("The field can only contain numbers");
return;
}
if(theValue.indexOf(".") != -1)
{
theValue = theValue.substring(0,(theValue.indexOf(".") + 3));
}
lnt = theValue.length;
if(lnt > maxLength )
{
if(theValue.indexOf(".") == -1) {
theValue = theValue.substring(0,maxLength);
}
else
{
theValue = theValue.substring(0,(maxLength+1));
}
lnt = theValue.length;
}
if(lnt > (maxLength-2) && theValue.indexOf(".") == -1)
{
first = theValue.substring(0,(maxLength-2));
second = theValue.substring((maxLength-2));
theValue = first + "." + second;
}
document.getElementById(id).value= theValue;
}